{
  "nbformat": 4,
  "nbformat_minor": 0,
  "metadata": {
    "colab": {
      "provenance": []
    },
    "kernelspec": {
      "name": "python3",
      "display_name": "Python 3"
    }
  },
  "cells": [
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "zkufh760uvF3"
      },
      "source": [
        "![JohnSnowLabs](https://nlp.johnsnowlabs.com/assets/images/logo.png)\n",
        "\n",
        "[![Open In Colab](https://colab.research.google.com/assets/colab-badge.svg)](https://colab.research.google.com/github/JohnSnowLabs/nlu/blob/master/examples/colab/Training/binary_text_classification/NLU_training_sentiment_classifier_demo_finanical_news.ipynb)\n",
        "\n",
        "\n",
        "\n",
        "# Training a Sentiment Analysis Classifier with NLU\n",
        "## 2 class Finance News sentiment classifier training\n",
        "With the [SentimentDL model](https://nlp.johnsnowlabs.com/docs/en/annotators#sentimentdl-multi-class-sentiment-analysis-annotator) from Spark NLP you can achieve State Of the Art results on any multi class text classification problem\n",
        "\n",
        "This notebook showcases the following features :\n",
        "\n",
        "- How to train the deep learning classifier\n",
        "- How to store a pipeline to disk\n",
        "- How to load the pipeline from disk (Enables NLU offline mode)\n",
        "\n",
        "You can achieve these results or even better on this dataset with training data:\n",
        "\n",
        "<br>\n",
        "\n",
        "![image.png]()\n",
        "\n",
        "\n",
        "\n",
        "\n",
        "You can achieve these results or even better on this dataset with test data:\n",
        "\n",
        "\n",
        "<br>\n",
        "\n",
        "\n",
        "![image.png]()"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "dur2drhW5Rvi"
      },
      "source": [
        "# 1. Install Java 8 and NLU"
      ]
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "hFGnBCHavltY"
      },
      "source": [
        "!pip install -q johnsnowlabs"
      ],
      "execution_count": null,
      "outputs": []
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "f4KkTfnR5Ugg"
      },
      "source": [
        "# 2. Download Finanical News  Sentiment dataset\n",
        "https://www.kaggle.com/ankurzing/sentiment-analysis-for-financial-news\n",
        "\n",
        "This dataset contains the sentiments for financial news headlines from the perspective of a retail investor. Further details about the dataset can be found in: Malo, P., Sinha, A., Takala, P., Korhonen, P. and Wallenius, J. (2014): “Good debt or bad debt: Detecting semantic orientations in economic texts.” Journal of the American Society for Information Science and Technology."
      ]
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "OrVb5ZMvvrQD"
      },
      "source": [
        "! wget https://s3.amazonaws.com/auxdata.johnsnowlabs.com/public/resources/en/classifier-dl/financial_news/all-data.csv\n"
      ],
      "execution_count": null,
      "outputs": []
    },
    {
      "cell_type": "code",
      "metadata": {
        "colab": {
          "base_uri": "https://localhost:8080/",
          "height": 424
        },
        "id": "y4xSRWIhwT28",
        "outputId": "4b2c74bd-7563-44ca-9201-d1e76f4899e3"
      },
      "source": [
        "import pandas as pd\n",
        "train_path = '/content/all-data.csv'\n",
        "\n",
        "train_df = pd.read_csv(train_path)\n",
        "# the text data to use for classification should be in a column named 'text'\n",
        "# the label column must have name 'y' name be of type str\n",
        "columns=['text','y']\n",
        "train_df = train_df[columns]\n",
        "train_df = train_df[~train_df[\"y\"].isin([\"neutral\"])]\n",
        "from sklearn.model_selection import train_test_split\n",
        "\n",
        "train_df, test_df = train_test_split(train_df, test_size=0.2)\n",
        "train_df"
      ],
      "execution_count": 3,
      "outputs": [
        {
          "output_type": "execute_result",
          "data": {
            "text/plain": [
              "                                                   text         y\n",
              "4631  The OMX Nordic 40 OMXN40 index , comprising th...  negative\n",
              "4512  Dubai Nokia has announced the launch of `` Com...  positive\n",
              "2860  credit 20 November 2009 - Finnish glass techno...  positive\n",
              "1780  HELSINKI AFX - Outokumpu said its technology u...  positive\n",
              "845   Helsingin Uutiset , Vantaan Sanomat and Lansiv...  positive\n",
              "...                                                 ...       ...\n",
              "186   EPS for the quarter was EUR0 .00 , as compared...  positive\n",
              "47    The company also estimates the already carried...  positive\n",
              "1492  A realignment of interests in the sector is cl...  positive\n",
              "2094                European traffic grew nearly 30 % .  positive\n",
              "4452  The period 's sales dropped to EUR30 .6 m from...  negative\n",
              "\n",
              "[1573 rows x 2 columns]"
            ],
            "text/html": [
              "\n",
              "  <div id=\"df-6c3c3b9d-ec02-42d1-be52-7b4a92856787\" class=\"colab-df-container\">\n",
              "    <div>\n",
              "<style scoped>\n",
              "    .dataframe tbody tr th:only-of-type {\n",
              "        vertical-align: middle;\n",
              "    }\n",
              "\n",
              "    .dataframe tbody tr th {\n",
              "        vertical-align: top;\n",
              "    }\n",
              "\n",
              "    .dataframe thead th {\n",
              "        text-align: right;\n",
              "    }\n",
              "</style>\n",
              "<table border=\"1\" class=\"dataframe\">\n",
              "  <thead>\n",
              "    <tr style=\"text-align: right;\">\n",
              "      <th></th>\n",
              "      <th>text</th>\n",
              "      <th>y</th>\n",
              "    </tr>\n",
              "  </thead>\n",
              "  <tbody>\n",
              "    <tr>\n",
              "      <th>4631</th>\n",
              "      <td>The OMX Nordic 40 OMXN40 index , comprising th...</td>\n",
              "      <td>negative</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>4512</th>\n",
              "      <td>Dubai Nokia has announced the launch of `` Com...</td>\n",
              "      <td>positive</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>2860</th>\n",
              "      <td>credit 20 November 2009 - Finnish glass techno...</td>\n",
              "      <td>positive</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>1780</th>\n",
              "      <td>HELSINKI AFX - Outokumpu said its technology u...</td>\n",
              "      <td>positive</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>845</th>\n",
              "      <td>Helsingin Uutiset , Vantaan Sanomat and Lansiv...</td>\n",
              "      <td>positive</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>...</th>\n",
              "      <td>...</td>\n",
              "      <td>...</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>186</th>\n",
              "      <td>EPS for the quarter was EUR0 .00 , as compared...</td>\n",
              "      <td>positive</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>47</th>\n",
              "      <td>The company also estimates the already carried...</td>\n",
              "      <td>positive</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>1492</th>\n",
              "      <td>A realignment of interests in the sector is cl...</td>\n",
              "      <td>positive</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>2094</th>\n",
              "      <td>European traffic grew nearly 30 % .</td>\n",
              "      <td>positive</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>4452</th>\n",
              "      <td>The period 's sales dropped to EUR30 .6 m from...</td>\n",
              "      <td>negative</td>\n",
              "    </tr>\n",
              "  </tbody>\n",
              "</table>\n",
              "<p>1573 rows × 2 columns</p>\n",
              "</div>\n",
              "    <div class=\"colab-df-buttons\">\n",
              "\n",
              "  <div class=\"colab-df-container\">\n",
              "    <button class=\"colab-df-convert\" onclick=\"convertToInteractive('df-6c3c3b9d-ec02-42d1-be52-7b4a92856787')\"\n",
              "            title=\"Convert this dataframe to an interactive table.\"\n",
              "            style=\"display:none;\">\n",
              "\n",
              "  <svg xmlns=\"http://www.w3.org/2000/svg\" height=\"24px\" viewBox=\"0 -960 960 960\">\n",
              "    <path d=\"M120-120v-720h720v720H120Zm60-500h600v-160H180v160Zm220 220h160v-160H400v160Zm0 220h160v-160H400v160ZM180-400h160v-160H180v160Zm440 0h160v-160H620v160ZM180-180h160v-160H180v160Zm440 0h160v-160H620v160Z\"/>\n",
              "  </svg>\n",
              "    </button>\n",
              "\n",
              "  <style>\n",
              "    .colab-df-container {\n",
              "      display:flex;\n",
              "      gap: 12px;\n",
              "    }\n",
              "\n",
              "    .colab-df-convert {\n",
              "      background-color: #E8F0FE;\n",
              "      border: none;\n",
              "      border-radius: 50%;\n",
              "      cursor: pointer;\n",
              "      display: none;\n",
              "      fill: #1967D2;\n",
              "      height: 32px;\n",
              "      padding: 0 0 0 0;\n",
              "      width: 32px;\n",
              "    }\n",
              "\n",
              "    .colab-df-convert:hover {\n",
              "      background-color: #E2EBFA;\n",
              "      box-shadow: 0px 1px 2px rgba(60, 64, 67, 0.3), 0px 1px 3px 1px rgba(60, 64, 67, 0.15);\n",
              "      fill: #174EA6;\n",
              "    }\n",
              "\n",
              "    .colab-df-buttons div {\n",
              "      margin-bottom: 4px;\n",
              "    }\n",
              "\n",
              "    [theme=dark] .colab-df-convert {\n",
              "      background-color: #3B4455;\n",
              "      fill: #D2E3FC;\n",
              "    }\n",
              "\n",
              "    [theme=dark] .colab-df-convert:hover {\n",
              "      background-color: #434B5C;\n",
              "      box-shadow: 0px 1px 3px 1px rgba(0, 0, 0, 0.15);\n",
              "      filter: drop-shadow(0px 1px 2px rgba(0, 0, 0, 0.3));\n",
              "      fill: #FFFFFF;\n",
              "    }\n",
              "  </style>\n",
              "\n",
              "    <script>\n",
              "      const buttonEl =\n",
              "        document.querySelector('#df-6c3c3b9d-ec02-42d1-be52-7b4a92856787 button.colab-df-convert');\n",
              "      buttonEl.style.display =\n",
              "        google.colab.kernel.accessAllowed ? 'block' : 'none';\n",
              "\n",
              "      async function convertToInteractive(key) {\n",
              "        const element = document.querySelector('#df-6c3c3b9d-ec02-42d1-be52-7b4a92856787');\n",
              "        const dataTable =\n",
              "          await google.colab.kernel.invokeFunction('convertToInteractive',\n",
              "                                                    [key], {});\n",
              "        if (!dataTable) return;\n",
              "\n",
              "        const docLinkHtml = 'Like what you see? Visit the ' +\n",
              "          '<a target=\"_blank\" href=https://colab.research.google.com/notebooks/data_table.ipynb>data table notebook</a>'\n",
              "          + ' to learn more about interactive tables.';\n",
              "        element.innerHTML = '';\n",
              "        dataTable['output_type'] = 'display_data';\n",
              "        await google.colab.output.renderOutput(dataTable, element);\n",
              "        const docLink = document.createElement('div');\n",
              "        docLink.innerHTML = docLinkHtml;\n",
              "        element.appendChild(docLink);\n",
              "      }\n",
              "    </script>\n",
              "  </div>\n",
              "\n",
              "\n",
              "<div id=\"df-05634492-c279-4bd3-a2de-20440fdfdaba\">\n",
              "  <button class=\"colab-df-quickchart\" onclick=\"quickchart('df-05634492-c279-4bd3-a2de-20440fdfdaba')\"\n",
              "            title=\"Suggest charts.\"\n",
              "            style=\"display:none;\">\n",
              "\n",
              "<svg xmlns=\"http://www.w3.org/2000/svg\" height=\"24px\"viewBox=\"0 0 24 24\"\n",
              "     width=\"24px\">\n",
              "    <g>\n",
              "        <path d=\"M19 3H5c-1.1 0-2 .9-2 2v14c0 1.1.9 2 2 2h14c1.1 0 2-.9 2-2V5c0-1.1-.9-2-2-2zM9 17H7v-7h2v7zm4 0h-2V7h2v10zm4 0h-2v-4h2v4z\"/>\n",
              "    </g>\n",
              "</svg>\n",
              "  </button>\n",
              "\n",
              "<style>\n",
              "  .colab-df-quickchart {\n",
              "      --bg-color: #E8F0FE;\n",
              "      --fill-color: #1967D2;\n",
              "      --hover-bg-color: #E2EBFA;\n",
              "      --hover-fill-color: #174EA6;\n",
              "      --disabled-fill-color: #AAA;\n",
              "      --disabled-bg-color: #DDD;\n",
              "  }\n",
              "\n",
              "  [theme=dark] .colab-df-quickchart {\n",
              "      --bg-color: #3B4455;\n",
              "      --fill-color: #D2E3FC;\n",
              "      --hover-bg-color: #434B5C;\n",
              "      --hover-fill-color: #FFFFFF;\n",
              "      --disabled-bg-color: #3B4455;\n",
              "      --disabled-fill-color: #666;\n",
              "  }\n",
              "\n",
              "  .colab-df-quickchart {\n",
              "    background-color: var(--bg-color);\n",
              "    border: none;\n",
              "    border-radius: 50%;\n",
              "    cursor: pointer;\n",
              "    display: none;\n",
              "    fill: var(--fill-color);\n",
              "    height: 32px;\n",
              "    padding: 0;\n",
              "    width: 32px;\n",
              "  }\n",
              "\n",
              "  .colab-df-quickchart:hover {\n",
              "    background-color: var(--hover-bg-color);\n",
              "    box-shadow: 0 1px 2px rgba(60, 64, 67, 0.3), 0 1px 3px 1px rgba(60, 64, 67, 0.15);\n",
              "    fill: var(--button-hover-fill-color);\n",
              "  }\n",
              "\n",
              "  .colab-df-quickchart-complete:disabled,\n",
              "  .colab-df-quickchart-complete:disabled:hover {\n",
              "    background-color: var(--disabled-bg-color);\n",
              "    fill: var(--disabled-fill-color);\n",
              "    box-shadow: none;\n",
              "  }\n",
              "\n",
              "  .colab-df-spinner {\n",
              "    border: 2px solid var(--fill-color);\n",
              "    border-color: transparent;\n",
              "    border-bottom-color: var(--fill-color);\n",
              "    animation:\n",
              "      spin 1s steps(1) infinite;\n",
              "  }\n",
              "\n",
              "  @keyframes spin {\n",
              "    0% {\n",
              "      border-color: transparent;\n",
              "      border-bottom-color: var(--fill-color);\n",
              "      border-left-color: var(--fill-color);\n",
              "    }\n",
              "    20% {\n",
              "      border-color: transparent;\n",
              "      border-left-color: var(--fill-color);\n",
              "      border-top-color: var(--fill-color);\n",
              "    }\n",
              "    30% {\n",
              "      border-color: transparent;\n",
              "      border-left-color: var(--fill-color);\n",
              "      border-top-color: var(--fill-color);\n",
              "      border-right-color: var(--fill-color);\n",
              "    }\n",
              "    40% {\n",
              "      border-color: transparent;\n",
              "      border-right-color: var(--fill-color);\n",
              "      border-top-color: var(--fill-color);\n",
              "    }\n",
              "    60% {\n",
              "      border-color: transparent;\n",
              "      border-right-color: var(--fill-color);\n",
              "    }\n",
              "    80% {\n",
              "      border-color: transparent;\n",
              "      border-right-color: var(--fill-color);\n",
              "      border-bottom-color: var(--fill-color);\n",
              "    }\n",
              "    90% {\n",
              "      border-color: transparent;\n",
              "      border-bottom-color: var(--fill-color);\n",
              "    }\n",
              "  }\n",
              "</style>\n",
              "\n",
              "  <script>\n",
              "    async function quickchart(key) {\n",
              "      const quickchartButtonEl =\n",
              "        document.querySelector('#' + key + ' button');\n",
              "      quickchartButtonEl.disabled = true;  // To prevent multiple clicks.\n",
              "      quickchartButtonEl.classList.add('colab-df-spinner');\n",
              "      try {\n",
              "        const charts = await google.colab.kernel.invokeFunction(\n",
              "            'suggestCharts', [key], {});\n",
              "      } catch (error) {\n",
              "        console.error('Error during call to suggestCharts:', error);\n",
              "      }\n",
              "      quickchartButtonEl.classList.remove('colab-df-spinner');\n",
              "      quickchartButtonEl.classList.add('colab-df-quickchart-complete');\n",
              "    }\n",
              "    (() => {\n",
              "      let quickchartButtonEl =\n",
              "        document.querySelector('#df-05634492-c279-4bd3-a2de-20440fdfdaba button');\n",
              "      quickchartButtonEl.style.display =\n",
              "        google.colab.kernel.accessAllowed ? 'block' : 'none';\n",
              "    })();\n",
              "  </script>\n",
              "</div>\n",
              "    </div>\n",
              "  </div>\n"
            ]
          },
          "metadata": {},
          "execution_count": 3
        }
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "0296Om2C5anY"
      },
      "source": [
        "# 3. Train Deep Learning Classifier using nlu.load('train.sentiment')\n",
        "\n",
        "You dataset label column should be named 'y' and the feature column with text data should be named 'text'"
      ]
    },
    {
      "cell_type": "code",
      "metadata": {
        "colab": {
          "base_uri": "https://localhost:8080/",
          "height": 1000
        },
        "id": "3ZIPkRkWftBG",
        "outputId": "cd7d4cb2-deba-4161-c04f-c93016fee93c"
      },
      "source": [
        "from johnsnowlabs import nlp\n",
        "from sklearn.metrics import classification_report\n",
        "\n",
        "# load a trainable pipeline by specifying the train. prefix  and fit it on a datset with label and text columns\n",
        "# by default the Universal Sentence Encoder (USE) Sentence embeddings are used for generation\n",
        "trainable_pipe = nlp.load('train.sentiment')\n",
        "fitted_pipe = trainable_pipe.fit(train_df.iloc[:50])\n",
        "\n",
        "# predict with the trainable pipeline on dataset and get predictions\n",
        "preds = fitted_pipe.predict(train_df.iloc[:50],output_level='document')\n",
        "#sentence detector that is part of the pipe generates sone NaNs. lets drop them first\n",
        "preds.dropna(inplace=True)\n",
        "print(classification_report(preds['y'], preds['sentiment']))\n",
        "\n",
        "preds"
      ],
      "execution_count": 4,
      "outputs": [
        {
          "output_type": "stream",
          "name": "stdout",
          "text": [
            "Warning::Spark Session already created, some configs may not take.\n",
            "sent_small_bert_L2_128 download started this may take some time.\n",
            "Approximate size to download 16.1 MB\n",
            "[OK!]\n",
            "              precision    recall  f1-score   support\n",
            "\n",
            "    negative       0.00      0.00      0.00        17\n",
            "    positive       0.66      1.00      0.80        33\n",
            "\n",
            "    accuracy                           0.66        50\n",
            "   macro avg       0.33      0.50      0.40        50\n",
            "weighted avg       0.44      0.66      0.52        50\n",
            "\n"
          ]
        },
        {
          "output_type": "execute_result",
          "data": {
            "text/plain": [
              "                                             document  \\\n",
              "0   The OMX Nordic 40 OMXN40 index , comprising th...   \n",
              "1   Dubai Nokia has announced the launch of `` Com...   \n",
              "2   credit 20 November 2009 - Finnish glass techno...   \n",
              "3   HELSINKI AFX - Outokumpu said its technology u...   \n",
              "4   Helsingin Uutiset , Vantaan Sanomat and Lansiv...   \n",
              "5   Operating profit totaled EUR 5.5 mn , up from ...   \n",
              "6   Excluding non-recurring items , pre-tax profit...   \n",
              "7   1 February 2011 - Finnish textile and clothing...   \n",
              "8   `` There 's the issue of thieves stealing them...   \n",
              "9   Estonian telecoms company Elisa 's customer nu...   \n",
              "10  Net sales for the financial year 2006 are expe...   \n",
              "11  55 workers in +_m+_l will be affected by the c...   \n",
              "12  The Helsinki-based company , which also owns t...   \n",
              "13  YIT lodged counter claims against Neste Oil to...   \n",
              "14  Kaido Kaare , general director for Atria Eesti...   \n",
              "15  Mobile phone shipments jumped 26 percent to al...   \n",
              "16  `` After this purchase , Cramo will become the...   \n",
              "17  The court found TelecomInvest 's arguments con...   \n",
              "18  Operating profit for 2009 lower than outlook p...   \n",
              "19  Vanhanen said the strike would be `` extremely...   \n",
              "20  Construction volumes meanwhile grow at a rate ...   \n",
              "21  Operating profit for the six-month period decr...   \n",
              "22  Raisio 's malting capacity was in full use in ...   \n",
              "23  Both operating profit and turnover for the six...   \n",
              "24  Our superior customer centricity and expertise...   \n",
              "25  Commission income rose by 25.7 % to EUR 16.1 m...   \n",
              "26  The personnel reduction will be carried out in...   \n",
              "27  The result will also be burdened by increased ...   \n",
              "28  Employees are also better prepared to answer c...   \n",
              "29  It generated an operating loss of EUR 96.3 mn ...   \n",
              "30  In addition , the company will reduce a maximu...   \n",
              "31  Forestries were also higher , driven by yester...   \n",
              "32  In the second quarter of 2010 , the group 's n...   \n",
              "33  It is a solid credit that has been compared to...   \n",
              "34  He said he has been losing five families a mon...   \n",
              "35  In Finland , media group Talentum will start p...   \n",
              "36  Finnish pharmaceuticals company Orion 's net s...   \n",
              "37  `` The margarine business has been put into go...   \n",
              "38  Operating profit excluding non-recurring items...   \n",
              "39  MD Henning Bahr of Stockmann Gruppen praises t...   \n",
              "40  Based on the first quarter result , existing o...   \n",
              "41  Both operating profit and net sales for the 12...   \n",
              "42  In Sweden , operating profit for the period un...   \n",
              "43  To our members and partners , the use of IT wi...   \n",
              "44  Of the sales price , a sales gain of some 3.1 ...   \n",
              "45    It is a disappointment to see the plan folded .   \n",
              "46  Progress Group , QPR 's representative in Saud...   \n",
              "47  The new agreement , which expands a long-estab...   \n",
              "48  With CapMan as a partner , we will be able to ...   \n",
              "49  `` Overall , we 're pleased with the startup c...   \n",
              "\n",
              "                 sentence_embedding_small_bert_L2_128 sentiment  \\\n",
              "0   [-0.5881205201148987, 0.19063492119312286, -0....  positive   \n",
              "1   [-0.37779635190963745, -0.20781250298023224, -...  positive   \n",
              "2   [-0.4517509937286377, 0.6735780239105225, -0.2...  positive   \n",
              "3   [-0.10504205524921417, 0.31528422236442566, -0...  positive   \n",
              "4   [-1.087294101715088, -0.1457926332950592, -0.1...  positive   \n",
              "5   [-0.643149197101593, -0.04868743568658829, -0....  positive   \n",
              "6   [-0.7197213172912598, 0.31680017709732056, -0....  positive   \n",
              "7   [-0.31616416573524475, 0.5464960336685181, -0....  positive   \n",
              "8   [-1.2100399732589722, 0.25674229860305786, 0.3...  positive   \n",
              "9   [-0.3009508550167084, 0.6154500842094421, -0.4...  positive   \n",
              "10  [-0.7339814305305481, 0.9638439416885376, -0.6...  positive   \n",
              "11  [-1.243334174156189, 0.8785222172737122, -0.93...  positive   \n",
              "12  [-0.7551414370536804, 0.16214342415332794, -0....  positive   \n",
              "13  [-1.143906831741333, 1.0500915050506592, -0.84...  positive   \n",
              "14  [-0.9822889566421509, 0.27106359601020813, -0....  positive   \n",
              "15  [-0.46120399236679077, 0.09638205915689468, -0...  positive   \n",
              "16  [-0.7024871706962585, 0.37345775961875916, -0....  positive   \n",
              "17  [-0.8505982756614685, -0.07158830016851425, 0....  positive   \n",
              "18  [-0.6575804352760315, 0.68410724401474, -0.230...  positive   \n",
              "19  [-0.7677791714668274, -0.44950076937675476, -0...  positive   \n",
              "20  [-1.4539079666137695, 0.1873081475496292, -0.8...  positive   \n",
              "21  [-1.0161586999893188, 0.548879861831665, -0.86...  positive   \n",
              "22  [-1.2556798458099365, 0.37126457691192627, -1....  positive   \n",
              "23  [-0.8761054873466492, 0.2913503050804138, -0.8...  positive   \n",
              "24  [-0.11308443546295166, 0.5551179647445679, -0....  positive   \n",
              "25  [-0.7847265601158142, 0.2198852002620697, -0.5...  positive   \n",
              "26  [-0.8359718918800354, -0.18021883070468903, -0...  positive   \n",
              "27  [-0.6881139278411865, 1.2389051914215088, -1.0...  positive   \n",
              "28  [-1.3386954069137573, 0.24523791670799255, -0....  positive   \n",
              "29  [-0.7223557829856873, 0.23957425355911255, -0....  positive   \n",
              "30  [-0.9004239439964294, 1.6903105974197388, -0.9...  positive   \n",
              "31  [-0.9628726840019226, 0.23581582307815552, 0.2...  positive   \n",
              "32  [-0.9420221447944641, 0.34946343302726746, -0....  positive   \n",
              "33  [-0.0682043731212616, 0.5560981035232544, -0.8...  positive   \n",
              "34  [-1.1294713020324707, 0.507931113243103, -0.73...  positive   \n",
              "35  [-0.6348045468330383, 0.3473186492919922, -0.2...  positive   \n",
              "36  [-0.8268173933029175, 0.19876690208911896, -0....  positive   \n",
              "37  [-0.6286064386367798, 0.48110127449035645, -0....  positive   \n",
              "38  [-0.7780808210372925, 0.021108699962496758, -0...  positive   \n",
              "39  [-0.39700981974601746, 0.9596268534660339, -0....  positive   \n",
              "40  [-0.7781174182891846, 0.9358287453651428, -1.0...  positive   \n",
              "41  [-0.7753643989562988, 0.8645752668380737, -0.6...  positive   \n",
              "42  [-0.8275543451309204, 0.10950104892253876, -0....  positive   \n",
              "43  [-0.798611581325531, 0.7145741581916809, -0.40...  positive   \n",
              "44  [-0.8446655869483948, 0.8184226751327515, -0.3...  positive   \n",
              "45  [-1.0249158143997192, 0.8160240054130554, 0.03...  positive   \n",
              "46  [-0.17222441732883453, 0.3021131455898285, -0....  positive   \n",
              "47  [-0.5851113796234131, 0.6877164244651794, -0.6...  positive   \n",
              "48  [-0.2812011241912842, 1.1173006296157837, -0.3...  positive   \n",
              "49  [-0.7001730799674988, 0.15320643782615662, 0.3...  positive   \n",
              "\n",
              "   sentiment_confidence                                               text  \\\n",
              "0                   7.0  The OMX Nordic 40 OMXN40 index , comprising th...   \n",
              "1                   2.0  Dubai Nokia has announced the launch of `` Com...   \n",
              "2                   5.0  credit 20 November 2009 - Finnish glass techno...   \n",
              "3                   1.0  HELSINKI AFX - Outokumpu said its technology u...   \n",
              "4                   2.0  Helsingin Uutiset , Vantaan Sanomat and Lansiv...   \n",
              "5                   1.0  Operating profit totaled EUR 5.5 mn , up from ...   \n",
              "6                   5.0  Excluding non-recurring items , pre-tax profit...   \n",
              "7                   8.0  1 February 2011 - Finnish textile and clothing...   \n",
              "8                   6.0  `` There 's the issue of thieves stealing them...   \n",
              "9                   6.0  Estonian telecoms company Elisa 's customer nu...   \n",
              "10                  3.0  Net sales for the financial year 2006 are expe...   \n",
              "11                  3.0  55 workers in +_m+_l will be affected by the c...   \n",
              "12                  1.0  The Helsinki-based company , which also owns t...   \n",
              "13                  1.0  YIT lodged counter claims against Neste Oil to...   \n",
              "14                  4.0  Kaido Kaare , general director for Atria Eesti...   \n",
              "15                  2.0  Mobile phone shipments jumped 26 percent to al...   \n",
              "16                  3.0  `` After this purchase , Cramo will become the...   \n",
              "17                  2.0  The court found TelecomInvest 's arguments con...   \n",
              "18                  7.0  Operating profit for 2009 lower than outlook p...   \n",
              "19                  4.0  Vanhanen said the strike would be `` extremely...   \n",
              "20                  8.0  Construction volumes meanwhile grow at a rate ...   \n",
              "21                  2.0  Operating profit for the six-month period decr...   \n",
              "22                  9.0  Raisio 's malting capacity was in full use in ...   \n",
              "23                  5.0  Both operating profit and turnover for the six...   \n",
              "24                  3.0  Our superior customer centricity and expertise...   \n",
              "25                  6.0  Commission income rose by 25.7 % to EUR 16.1 m...   \n",
              "26                  8.0  The personnel reduction will be carried out in...   \n",
              "27                  9.0  The result will also be burdened by increased ...   \n",
              "28                  2.0  Employees are also better prepared to answer c...   \n",
              "29                  2.0  It generated an operating loss of EUR 96.3 mn ...   \n",
              "30                  2.0  In addition , the company will reduce a maximu...   \n",
              "31                  4.0  Forestries were also higher , driven by yester...   \n",
              "32                  3.0  In the second quarter of 2010 , the group 's n...   \n",
              "33                  2.0  It is a solid credit that has been compared to...   \n",
              "34                  9.0  He said he has been losing five families a mon...   \n",
              "35                  3.0  In Finland , media group Talentum will start p...   \n",
              "36                  1.0  Finnish pharmaceuticals company Orion 's net s...   \n",
              "37                  2.0  `` The margarine business has been put into go...   \n",
              "38                  2.0  Operating profit excluding non-recurring items...   \n",
              "39                  1.0  MD Henning Bahr of Stockmann Gruppen praises t...   \n",
              "40                  9.0  Based on the first quarter result , existing o...   \n",
              "41                  3.0  Both operating profit and net sales for the 12...   \n",
              "42                  3.0  In Sweden , operating profit for the period un...   \n",
              "43                  3.0  To our members and partners , the use of IT wi...   \n",
              "44                  1.0  Of the sales price , a sales gain of some 3.1 ...   \n",
              "45                  1.0    It is a disappointment to see the plan folded .   \n",
              "46                  9.0  Progress Group , QPR 's representative in Saud...   \n",
              "47                  9.0  The new agreement , which expands a long-estab...   \n",
              "48                  4.0  With CapMan as a partner , we will be able to ...   \n",
              "49                  2.0  `` Overall , we 're pleased with the startup c...   \n",
              "\n",
              "           y  \n",
              "0   negative  \n",
              "1   positive  \n",
              "2   positive  \n",
              "3   positive  \n",
              "4   positive  \n",
              "5   positive  \n",
              "6   positive  \n",
              "7   positive  \n",
              "8   negative  \n",
              "9   positive  \n",
              "10  negative  \n",
              "11  negative  \n",
              "12  positive  \n",
              "13  negative  \n",
              "14  positive  \n",
              "15  positive  \n",
              "16  positive  \n",
              "17  positive  \n",
              "18  negative  \n",
              "19  negative  \n",
              "20  positive  \n",
              "21  negative  \n",
              "22  positive  \n",
              "23  positive  \n",
              "24  positive  \n",
              "25  positive  \n",
              "26  negative  \n",
              "27  negative  \n",
              "28  positive  \n",
              "29  negative  \n",
              "30  negative  \n",
              "31  positive  \n",
              "32  positive  \n",
              "33  positive  \n",
              "34  negative  \n",
              "35  negative  \n",
              "36  positive  \n",
              "37  positive  \n",
              "38  negative  \n",
              "39  positive  \n",
              "40  negative  \n",
              "41  positive  \n",
              "42  positive  \n",
              "43  positive  \n",
              "44  positive  \n",
              "45  negative  \n",
              "46  positive  \n",
              "47  positive  \n",
              "48  positive  \n",
              "49  positive  "
            ],
            "text/html": [
              "\n",
              "  <div id=\"df-3386a694-33e3-4c05-8fb4-57ec574b286b\" class=\"colab-df-container\">\n",
              "    <div>\n",
              "<style scoped>\n",
              "    .dataframe tbody tr th:only-of-type {\n",
              "        vertical-align: middle;\n",
              "    }\n",
              "\n",
              "    .dataframe tbody tr th {\n",
              "        vertical-align: top;\n",
              "    }\n",
              "\n",
              "    .dataframe thead th {\n",
              "        text-align: right;\n",
              "    }\n",
              "</style>\n",
              "<table border=\"1\" class=\"dataframe\">\n",
              "  <thead>\n",
              "    <tr style=\"text-align: right;\">\n",
              "      <th></th>\n",
              "      <th>document</th>\n",
              "      <th>sentence_embedding_small_bert_L2_128</th>\n",
              "      <th>sentiment</th>\n",
              "      <th>sentiment_confidence</th>\n",
              "      <th>text</th>\n",
              "      <th>y</th>\n",
              "    </tr>\n",
              "  </thead>\n",
              "  <tbody>\n",
              "    <tr>\n",
              "      <th>0</th>\n",
              "      <td>The OMX Nordic 40 OMXN40 index , comprising th...</td>\n",
              "      <td>[-0.5881205201148987, 0.19063492119312286, -0....</td>\n",
              "      <td>positive</td>\n",
              "      <td>7.0</td>\n",
              "      <td>The OMX Nordic 40 OMXN40 index , comprising th...</td>\n",
              "      <td>negative</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>1</th>\n",
              "      <td>Dubai Nokia has announced the launch of `` Com...</td>\n",
              "      <td>[-0.37779635190963745, -0.20781250298023224, -...</td>\n",
              "      <td>positive</td>\n",
              "      <td>2.0</td>\n",
              "      <td>Dubai Nokia has announced the launch of `` Com...</td>\n",
              "      <td>positive</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>2</th>\n",
              "      <td>credit 20 November 2009 - Finnish glass techno...</td>\n",
              "      <td>[-0.4517509937286377, 0.6735780239105225, -0.2...</td>\n",
              "      <td>positive</td>\n",
              "      <td>5.0</td>\n",
              "      <td>credit 20 November 2009 - Finnish glass techno...</td>\n",
              "      <td>positive</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>3</th>\n",
              "      <td>HELSINKI AFX - Outokumpu said its technology u...</td>\n",
              "      <td>[-0.10504205524921417, 0.31528422236442566, -0...</td>\n",
              "      <td>positive</td>\n",
              "      <td>1.0</td>\n",
              "      <td>HELSINKI AFX - Outokumpu said its technology u...</td>\n",
              "      <td>positive</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>4</th>\n",
              "      <td>Helsingin Uutiset , Vantaan Sanomat and Lansiv...</td>\n",
              "      <td>[-1.087294101715088, -0.1457926332950592, -0.1...</td>\n",
              "      <td>positive</td>\n",
              "      <td>2.0</td>\n",
              "      <td>Helsingin Uutiset , Vantaan Sanomat and Lansiv...</td>\n",
              "      <td>positive</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>5</th>\n",
              "      <td>Operating profit totaled EUR 5.5 mn , up from ...</td>\n",
              "      <td>[-0.643149197101593, -0.04868743568658829, -0....</td>\n",
              "      <td>positive</td>\n",
              "      <td>1.0</td>\n",
              "      <td>Operating profit totaled EUR 5.5 mn , up from ...</td>\n",
              "      <td>positive</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>6</th>\n",
              "      <td>Excluding non-recurring items , pre-tax profit...</td>\n",
              "      <td>[-0.7197213172912598, 0.31680017709732056, -0....</td>\n",
              "      <td>positive</td>\n",
              "      <td>5.0</td>\n",
              "      <td>Excluding non-recurring items , pre-tax profit...</td>\n",
              "      <td>positive</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>7</th>\n",
              "      <td>1 February 2011 - Finnish textile and clothing...</td>\n",
              "      <td>[-0.31616416573524475, 0.5464960336685181, -0....</td>\n",
              "      <td>positive</td>\n",
              "      <td>8.0</td>\n",
              "      <td>1 February 2011 - Finnish textile and clothing...</td>\n",
              "      <td>positive</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>8</th>\n",
              "      <td>`` There 's the issue of thieves stealing them...</td>\n",
              "      <td>[-1.2100399732589722, 0.25674229860305786, 0.3...</td>\n",
              "      <td>positive</td>\n",
              "      <td>6.0</td>\n",
              "      <td>`` There 's the issue of thieves stealing them...</td>\n",
              "      <td>negative</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>9</th>\n",
              "      <td>Estonian telecoms company Elisa 's customer nu...</td>\n",
              "      <td>[-0.3009508550167084, 0.6154500842094421, -0.4...</td>\n",
              "      <td>positive</td>\n",
              "      <td>6.0</td>\n",
              "      <td>Estonian telecoms company Elisa 's customer nu...</td>\n",
              "      <td>positive</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>10</th>\n",
              "      <td>Net sales for the financial year 2006 are expe...</td>\n",
              "      <td>[-0.7339814305305481, 0.9638439416885376, -0.6...</td>\n",
              "      <td>positive</td>\n",
              "      <td>3.0</td>\n",
              "      <td>Net sales for the financial year 2006 are expe...</td>\n",
              "      <td>negative</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>11</th>\n",
              "      <td>55 workers in +_m+_l will be affected by the c...</td>\n",
              "      <td>[-1.243334174156189, 0.8785222172737122, -0.93...</td>\n",
              "      <td>positive</td>\n",
              "      <td>3.0</td>\n",
              "      <td>55 workers in +_m+_l will be affected by the c...</td>\n",
              "      <td>negative</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>12</th>\n",
              "      <td>The Helsinki-based company , which also owns t...</td>\n",
              "      <td>[-0.7551414370536804, 0.16214342415332794, -0....</td>\n",
              "      <td>positive</td>\n",
              "      <td>1.0</td>\n",
              "      <td>The Helsinki-based company , which also owns t...</td>\n",
              "      <td>positive</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>13</th>\n",
              "      <td>YIT lodged counter claims against Neste Oil to...</td>\n",
              "      <td>[-1.143906831741333, 1.0500915050506592, -0.84...</td>\n",
              "      <td>positive</td>\n",
              "      <td>1.0</td>\n",
              "      <td>YIT lodged counter claims against Neste Oil to...</td>\n",
              "      <td>negative</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>14</th>\n",
              "      <td>Kaido Kaare , general director for Atria Eesti...</td>\n",
              "      <td>[-0.9822889566421509, 0.27106359601020813, -0....</td>\n",
              "      <td>positive</td>\n",
              "      <td>4.0</td>\n",
              "      <td>Kaido Kaare , general director for Atria Eesti...</td>\n",
              "      <td>positive</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>15</th>\n",
              "      <td>Mobile phone shipments jumped 26 percent to al...</td>\n",
              "      <td>[-0.46120399236679077, 0.09638205915689468, -0...</td>\n",
              "      <td>positive</td>\n",
              "      <td>2.0</td>\n",
              "      <td>Mobile phone shipments jumped 26 percent to al...</td>\n",
              "      <td>positive</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>16</th>\n",
              "      <td>`` After this purchase , Cramo will become the...</td>\n",
              "      <td>[-0.7024871706962585, 0.37345775961875916, -0....</td>\n",
              "      <td>positive</td>\n",
              "      <td>3.0</td>\n",
              "      <td>`` After this purchase , Cramo will become the...</td>\n",
              "      <td>positive</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>17</th>\n",
              "      <td>The court found TelecomInvest 's arguments con...</td>\n",
              "      <td>[-0.8505982756614685, -0.07158830016851425, 0....</td>\n",
              "      <td>positive</td>\n",
              "      <td>2.0</td>\n",
              "      <td>The court found TelecomInvest 's arguments con...</td>\n",
              "      <td>positive</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>18</th>\n",
              "      <td>Operating profit for 2009 lower than outlook p...</td>\n",
              "      <td>[-0.6575804352760315, 0.68410724401474, -0.230...</td>\n",
              "      <td>positive</td>\n",
              "      <td>7.0</td>\n",
              "      <td>Operating profit for 2009 lower than outlook p...</td>\n",
              "      <td>negative</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>19</th>\n",
              "      <td>Vanhanen said the strike would be `` extremely...</td>\n",
              "      <td>[-0.7677791714668274, -0.44950076937675476, -0...</td>\n",
              "      <td>positive</td>\n",
              "      <td>4.0</td>\n",
              "      <td>Vanhanen said the strike would be `` extremely...</td>\n",
              "      <td>negative</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>20</th>\n",
              "      <td>Construction volumes meanwhile grow at a rate ...</td>\n",
              "      <td>[-1.4539079666137695, 0.1873081475496292, -0.8...</td>\n",
              "      <td>positive</td>\n",
              "      <td>8.0</td>\n",
              "      <td>Construction volumes meanwhile grow at a rate ...</td>\n",
              "      <td>positive</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>21</th>\n",
              "      <td>Operating profit for the six-month period decr...</td>\n",
              "      <td>[-1.0161586999893188, 0.548879861831665, -0.86...</td>\n",
              "      <td>positive</td>\n",
              "      <td>2.0</td>\n",
              "      <td>Operating profit for the six-month period decr...</td>\n",
              "      <td>negative</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>22</th>\n",
              "      <td>Raisio 's malting capacity was in full use in ...</td>\n",
              "      <td>[-1.2556798458099365, 0.37126457691192627, -1....</td>\n",
              "      <td>positive</td>\n",
              "      <td>9.0</td>\n",
              "      <td>Raisio 's malting capacity was in full use in ...</td>\n",
              "      <td>positive</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>23</th>\n",
              "      <td>Both operating profit and turnover for the six...</td>\n",
              "      <td>[-0.8761054873466492, 0.2913503050804138, -0.8...</td>\n",
              "      <td>positive</td>\n",
              "      <td>5.0</td>\n",
              "      <td>Both operating profit and turnover for the six...</td>\n",
              "      <td>positive</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>24</th>\n",
              "      <td>Our superior customer centricity and expertise...</td>\n",
              "      <td>[-0.11308443546295166, 0.5551179647445679, -0....</td>\n",
              "      <td>positive</td>\n",
              "      <td>3.0</td>\n",
              "      <td>Our superior customer centricity and expertise...</td>\n",
              "      <td>positive</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>25</th>\n",
              "      <td>Commission income rose by 25.7 % to EUR 16.1 m...</td>\n",
              "      <td>[-0.7847265601158142, 0.2198852002620697, -0.5...</td>\n",
              "      <td>positive</td>\n",
              "      <td>6.0</td>\n",
              "      <td>Commission income rose by 25.7 % to EUR 16.1 m...</td>\n",
              "      <td>positive</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>26</th>\n",
              "      <td>The personnel reduction will be carried out in...</td>\n",
              "      <td>[-0.8359718918800354, -0.18021883070468903, -0...</td>\n",
              "      <td>positive</td>\n",
              "      <td>8.0</td>\n",
              "      <td>The personnel reduction will be carried out in...</td>\n",
              "      <td>negative</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>27</th>\n",
              "      <td>The result will also be burdened by increased ...</td>\n",
              "      <td>[-0.6881139278411865, 1.2389051914215088, -1.0...</td>\n",
              "      <td>positive</td>\n",
              "      <td>9.0</td>\n",
              "      <td>The result will also be burdened by increased ...</td>\n",
              "      <td>negative</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>28</th>\n",
              "      <td>Employees are also better prepared to answer c...</td>\n",
              "      <td>[-1.3386954069137573, 0.24523791670799255, -0....</td>\n",
              "      <td>positive</td>\n",
              "      <td>2.0</td>\n",
              "      <td>Employees are also better prepared to answer c...</td>\n",
              "      <td>positive</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>29</th>\n",
              "      <td>It generated an operating loss of EUR 96.3 mn ...</td>\n",
              "      <td>[-0.7223557829856873, 0.23957425355911255, -0....</td>\n",
              "      <td>positive</td>\n",
              "      <td>2.0</td>\n",
              "      <td>It generated an operating loss of EUR 96.3 mn ...</td>\n",
              "      <td>negative</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>30</th>\n",
              "      <td>In addition , the company will reduce a maximu...</td>\n",
              "      <td>[-0.9004239439964294, 1.6903105974197388, -0.9...</td>\n",
              "      <td>positive</td>\n",
              "      <td>2.0</td>\n",
              "      <td>In addition , the company will reduce a maximu...</td>\n",
              "      <td>negative</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>31</th>\n",
              "      <td>Forestries were also higher , driven by yester...</td>\n",
              "      <td>[-0.9628726840019226, 0.23581582307815552, 0.2...</td>\n",
              "      <td>positive</td>\n",
              "      <td>4.0</td>\n",
              "      <td>Forestries were also higher , driven by yester...</td>\n",
              "      <td>positive</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>32</th>\n",
              "      <td>In the second quarter of 2010 , the group 's n...</td>\n",
              "      <td>[-0.9420221447944641, 0.34946343302726746, -0....</td>\n",
              "      <td>positive</td>\n",
              "      <td>3.0</td>\n",
              "      <td>In the second quarter of 2010 , the group 's n...</td>\n",
              "      <td>positive</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>33</th>\n",
              "      <td>It is a solid credit that has been compared to...</td>\n",
              "      <td>[-0.0682043731212616, 0.5560981035232544, -0.8...</td>\n",
              "      <td>positive</td>\n",
              "      <td>2.0</td>\n",
              "      <td>It is a solid credit that has been compared to...</td>\n",
              "      <td>positive</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>34</th>\n",
              "      <td>He said he has been losing five families a mon...</td>\n",
              "      <td>[-1.1294713020324707, 0.507931113243103, -0.73...</td>\n",
              "      <td>positive</td>\n",
              "      <td>9.0</td>\n",
              "      <td>He said he has been losing five families a mon...</td>\n",
              "      <td>negative</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>35</th>\n",
              "      <td>In Finland , media group Talentum will start p...</td>\n",
              "      <td>[-0.6348045468330383, 0.3473186492919922, -0.2...</td>\n",
              "      <td>positive</td>\n",
              "      <td>3.0</td>\n",
              "      <td>In Finland , media group Talentum will start p...</td>\n",
              "      <td>negative</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>36</th>\n",
              "      <td>Finnish pharmaceuticals company Orion 's net s...</td>\n",
              "      <td>[-0.8268173933029175, 0.19876690208911896, -0....</td>\n",
              "      <td>positive</td>\n",
              "      <td>1.0</td>\n",
              "      <td>Finnish pharmaceuticals company Orion 's net s...</td>\n",
              "      <td>positive</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>37</th>\n",
              "      <td>`` The margarine business has been put into go...</td>\n",
              "      <td>[-0.6286064386367798, 0.48110127449035645, -0....</td>\n",
              "      <td>positive</td>\n",
              "      <td>2.0</td>\n",
              "      <td>`` The margarine business has been put into go...</td>\n",
              "      <td>positive</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>38</th>\n",
              "      <td>Operating profit excluding non-recurring items...</td>\n",
              "      <td>[-0.7780808210372925, 0.021108699962496758, -0...</td>\n",
              "      <td>positive</td>\n",
              "      <td>2.0</td>\n",
              "      <td>Operating profit excluding non-recurring items...</td>\n",
              "      <td>negative</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>39</th>\n",
              "      <td>MD Henning Bahr of Stockmann Gruppen praises t...</td>\n",
              "      <td>[-0.39700981974601746, 0.9596268534660339, -0....</td>\n",
              "      <td>positive</td>\n",
              "      <td>1.0</td>\n",
              "      <td>MD Henning Bahr of Stockmann Gruppen praises t...</td>\n",
              "      <td>positive</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>40</th>\n",
              "      <td>Based on the first quarter result , existing o...</td>\n",
              "      <td>[-0.7781174182891846, 0.9358287453651428, -1.0...</td>\n",
              "      <td>positive</td>\n",
              "      <td>9.0</td>\n",
              "      <td>Based on the first quarter result , existing o...</td>\n",
              "      <td>negative</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>41</th>\n",
              "      <td>Both operating profit and net sales for the 12...</td>\n",
              "      <td>[-0.7753643989562988, 0.8645752668380737, -0.6...</td>\n",
              "      <td>positive</td>\n",
              "      <td>3.0</td>\n",
              "      <td>Both operating profit and net sales for the 12...</td>\n",
              "      <td>positive</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>42</th>\n",
              "      <td>In Sweden , operating profit for the period un...</td>\n",
              "      <td>[-0.8275543451309204, 0.10950104892253876, -0....</td>\n",
              "      <td>positive</td>\n",
              "      <td>3.0</td>\n",
              "      <td>In Sweden , operating profit for the period un...</td>\n",
              "      <td>positive</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>43</th>\n",
              "      <td>To our members and partners , the use of IT wi...</td>\n",
              "      <td>[-0.798611581325531, 0.7145741581916809, -0.40...</td>\n",
              "      <td>positive</td>\n",
              "      <td>3.0</td>\n",
              "      <td>To our members and partners , the use of IT wi...</td>\n",
              "      <td>positive</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>44</th>\n",
              "      <td>Of the sales price , a sales gain of some 3.1 ...</td>\n",
              "      <td>[-0.8446655869483948, 0.8184226751327515, -0.3...</td>\n",
              "      <td>positive</td>\n",
              "      <td>1.0</td>\n",
              "      <td>Of the sales price , a sales gain of some 3.1 ...</td>\n",
              "      <td>positive</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>45</th>\n",
              "      <td>It is a disappointment to see the plan folded .</td>\n",
              "      <td>[-1.0249158143997192, 0.8160240054130554, 0.03...</td>\n",
              "      <td>positive</td>\n",
              "      <td>1.0</td>\n",
              "      <td>It is a disappointment to see the plan folded .</td>\n",
              "      <td>negative</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>46</th>\n",
              "      <td>Progress Group , QPR 's representative in Saud...</td>\n",
              "      <td>[-0.17222441732883453, 0.3021131455898285, -0....</td>\n",
              "      <td>positive</td>\n",
              "      <td>9.0</td>\n",
              "      <td>Progress Group , QPR 's representative in Saud...</td>\n",
              "      <td>positive</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>47</th>\n",
              "      <td>The new agreement , which expands a long-estab...</td>\n",
              "      <td>[-0.5851113796234131, 0.6877164244651794, -0.6...</td>\n",
              "      <td>positive</td>\n",
              "      <td>9.0</td>\n",
              "      <td>The new agreement , which expands a long-estab...</td>\n",
              "      <td>positive</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>48</th>\n",
              "      <td>With CapMan as a partner , we will be able to ...</td>\n",
              "      <td>[-0.2812011241912842, 1.1173006296157837, -0.3...</td>\n",
              "      <td>positive</td>\n",
              "      <td>4.0</td>\n",
              "      <td>With CapMan as a partner , we will be able to ...</td>\n",
              "      <td>positive</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>49</th>\n",
              "      <td>`` Overall , we 're pleased with the startup c...</td>\n",
              "      <td>[-0.7001730799674988, 0.15320643782615662, 0.3...</td>\n",
              "      <td>positive</td>\n",
              "      <td>2.0</td>\n",
              "      <td>`` Overall , we 're pleased with the startup c...</td>\n",
              "      <td>positive</td>\n",
              "    </tr>\n",
              "  </tbody>\n",
              "</table>\n",
              "</div>\n",
              "    <div class=\"colab-df-buttons\">\n",
              "\n",
              "  <div class=\"colab-df-container\">\n",
              "    <button class=\"colab-df-convert\" onclick=\"convertToInteractive('df-3386a694-33e3-4c05-8fb4-57ec574b286b')\"\n",
              "            title=\"Convert this dataframe to an interactive table.\"\n",
              "            style=\"display:none;\">\n",
              "\n",
              "  <svg xmlns=\"http://www.w3.org/2000/svg\" height=\"24px\" viewBox=\"0 -960 960 960\">\n",
              "    <path d=\"M120-120v-720h720v720H120Zm60-500h600v-160H180v160Zm220 220h160v-160H400v160Zm0 220h160v-160H400v160ZM180-400h160v-160H180v160Zm440 0h160v-160H620v160ZM180-180h160v-160H180v160Zm440 0h160v-160H620v160Z\"/>\n",
              "  </svg>\n",
              "    </button>\n",
              "\n",
              "  <style>\n",
              "    .colab-df-container {\n",
              "      display:flex;\n",
              "      gap: 12px;\n",
              "    }\n",
              "\n",
              "    .colab-df-convert {\n",
              "      background-color: #E8F0FE;\n",
              "      border: none;\n",
              "      border-radius: 50%;\n",
              "      cursor: pointer;\n",
              "      display: none;\n",
              "      fill: #1967D2;\n",
              "      height: 32px;\n",
              "      padding: 0 0 0 0;\n",
              "      width: 32px;\n",
              "    }\n",
              "\n",
              "    .colab-df-convert:hover {\n",
              "      background-color: #E2EBFA;\n",
              "      box-shadow: 0px 1px 2px rgba(60, 64, 67, 0.3), 0px 1px 3px 1px rgba(60, 64, 67, 0.15);\n",
              "      fill: #174EA6;\n",
              "    }\n",
              "\n",
              "    .colab-df-buttons div {\n",
              "      margin-bottom: 4px;\n",
              "    }\n",
              "\n",
              "    [theme=dark] .colab-df-convert {\n",
              "      background-color: #3B4455;\n",
              "      fill: #D2E3FC;\n",
              "    }\n",
              "\n",
              "    [theme=dark] .colab-df-convert:hover {\n",
              "      background-color: #434B5C;\n",
              "      box-shadow: 0px 1px 3px 1px rgba(0, 0, 0, 0.15);\n",
              "      filter: drop-shadow(0px 1px 2px rgba(0, 0, 0, 0.3));\n",
              "      fill: #FFFFFF;\n",
              "    }\n",
              "  </style>\n",
              "\n",
              "    <script>\n",
              "      const buttonEl =\n",
              "        document.querySelector('#df-3386a694-33e3-4c05-8fb4-57ec574b286b button.colab-df-convert');\n",
              "      buttonEl.style.display =\n",
              "        google.colab.kernel.accessAllowed ? 'block' : 'none';\n",
              "\n",
              "      async function convertToInteractive(key) {\n",
              "        const element = document.querySelector('#df-3386a694-33e3-4c05-8fb4-57ec574b286b');\n",
              "        const dataTable =\n",
              "          await google.colab.kernel.invokeFunction('convertToInteractive',\n",
              "                                                    [key], {});\n",
              "        if (!dataTable) return;\n",
              "\n",
              "        const docLinkHtml = 'Like what you see? Visit the ' +\n",
              "          '<a target=\"_blank\" href=https://colab.research.google.com/notebooks/data_table.ipynb>data table notebook</a>'\n",
              "          + ' to learn more about interactive tables.';\n",
              "        element.innerHTML = '';\n",
              "        dataTable['output_type'] = 'display_data';\n",
              "        await google.colab.output.renderOutput(dataTable, element);\n",
              "        const docLink = document.createElement('div');\n",
              "        docLink.innerHTML = docLinkHtml;\n",
              "        element.appendChild(docLink);\n",
              "      }\n",
              "    </script>\n",
              "  </div>\n",
              "\n",
              "\n",
              "<div id=\"df-a0b84fa4-8336-434c-bdb5-0c003e833710\">\n",
              "  <button class=\"colab-df-quickchart\" onclick=\"quickchart('df-a0b84fa4-8336-434c-bdb5-0c003e833710')\"\n",
              "            title=\"Suggest charts.\"\n",
              "            style=\"display:none;\">\n",
              "\n",
              "<svg xmlns=\"http://www.w3.org/2000/svg\" height=\"24px\"viewBox=\"0 0 24 24\"\n",
              "     width=\"24px\">\n",
              "    <g>\n",
              "        <path d=\"M19 3H5c-1.1 0-2 .9-2 2v14c0 1.1.9 2 2 2h14c1.1 0 2-.9 2-2V5c0-1.1-.9-2-2-2zM9 17H7v-7h2v7zm4 0h-2V7h2v10zm4 0h-2v-4h2v4z\"/>\n",
              "    </g>\n",
              "</svg>\n",
              "  </button>\n",
              "\n",
              "<style>\n",
              "  .colab-df-quickchart {\n",
              "      --bg-color: #E8F0FE;\n",
              "      --fill-color: #1967D2;\n",
              "      --hover-bg-color: #E2EBFA;\n",
              "      --hover-fill-color: #174EA6;\n",
              "      --disabled-fill-color: #AAA;\n",
              "      --disabled-bg-color: #DDD;\n",
              "  }\n",
              "\n",
              "  [theme=dark] .colab-df-quickchart {\n",
              "      --bg-color: #3B4455;\n",
              "      --fill-color: #D2E3FC;\n",
              "      --hover-bg-color: #434B5C;\n",
              "      --hover-fill-color: #FFFFFF;\n",
              "      --disabled-bg-color: #3B4455;\n",
              "      --disabled-fill-color: #666;\n",
              "  }\n",
              "\n",
              "  .colab-df-quickchart {\n",
              "    background-color: var(--bg-color);\n",
              "    border: none;\n",
              "    border-radius: 50%;\n",
              "    cursor: pointer;\n",
              "    display: none;\n",
              "    fill: var(--fill-color);\n",
              "    height: 32px;\n",
              "    padding: 0;\n",
              "    width: 32px;\n",
              "  }\n",
              "\n",
              "  .colab-df-quickchart:hover {\n",
              "    background-color: var(--hover-bg-color);\n",
              "    box-shadow: 0 1px 2px rgba(60, 64, 67, 0.3), 0 1px 3px 1px rgba(60, 64, 67, 0.15);\n",
              "    fill: var(--button-hover-fill-color);\n",
              "  }\n",
              "\n",
              "  .colab-df-quickchart-complete:disabled,\n",
              "  .colab-df-quickchart-complete:disabled:hover {\n",
              "    background-color: var(--disabled-bg-color);\n",
              "    fill: var(--disabled-fill-color);\n",
              "    box-shadow: none;\n",
              "  }\n",
              "\n",
              "  .colab-df-spinner {\n",
              "    border: 2px solid var(--fill-color);\n",
              "    border-color: transparent;\n",
              "    border-bottom-color: var(--fill-color);\n",
              "    animation:\n",
              "      spin 1s steps(1) infinite;\n",
              "  }\n",
              "\n",
              "  @keyframes spin {\n",
              "    0% {\n",
              "      border-color: transparent;\n",
              "      border-bottom-color: var(--fill-color);\n",
              "      border-left-color: var(--fill-color);\n",
              "    }\n",
              "    20% {\n",
              "      border-color: transparent;\n",
              "      border-left-color: var(--fill-color);\n",
              "      border-top-color: var(--fill-color);\n",
              "    }\n",
              "    30% {\n",
              "      border-color: transparent;\n",
              "      border-left-color: var(--fill-color);\n",
              "      border-top-color: var(--fill-color);\n",
              "      border-right-color: var(--fill-color);\n",
              "    }\n",
              "    40% {\n",
              "      border-color: transparent;\n",
              "      border-right-color: var(--fill-color);\n",
              "      border-top-color: var(--fill-color);\n",
              "    }\n",
              "    60% {\n",
              "      border-color: transparent;\n",
              "      border-right-color: var(--fill-color);\n",
              "    }\n",
              "    80% {\n",
              "      border-color: transparent;\n",
              "      border-right-color: var(--fill-color);\n",
              "      border-bottom-color: var(--fill-color);\n",
              "    }\n",
              "    90% {\n",
              "      border-color: transparent;\n",
              "      border-bottom-color: var(--fill-color);\n",
              "    }\n",
              "  }\n",
              "</style>\n",
              "\n",
              "  <script>\n",
              "    async function quickchart(key) {\n",
              "      const quickchartButtonEl =\n",
              "        document.querySelector('#' + key + ' button');\n",
              "      quickchartButtonEl.disabled = true;  // To prevent multiple clicks.\n",
              "      quickchartButtonEl.classList.add('colab-df-spinner');\n",
              "      try {\n",
              "        const charts = await google.colab.kernel.invokeFunction(\n",
              "            'suggestCharts', [key], {});\n",
              "      } catch (error) {\n",
              "        console.error('Error during call to suggestCharts:', error);\n",
              "      }\n",
              "      quickchartButtonEl.classList.remove('colab-df-spinner');\n",
              "      quickchartButtonEl.classList.add('colab-df-quickchart-complete');\n",
              "    }\n",
              "    (() => {\n",
              "      let quickchartButtonEl =\n",
              "        document.querySelector('#df-a0b84fa4-8336-434c-bdb5-0c003e833710 button');\n",
              "      quickchartButtonEl.style.display =\n",
              "        google.colab.kernel.accessAllowed ? 'block' : 'none';\n",
              "    })();\n",
              "  </script>\n",
              "</div>\n",
              "    </div>\n",
              "  </div>\n"
            ]
          },
          "metadata": {},
          "execution_count": 4
        }
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "lVyOE2wV0fw_"
      },
      "source": [
        "# 4. Test the fitted pipe on new example"
      ]
    },
    {
      "cell_type": "code",
      "metadata": {
        "colab": {
          "base_uri": "https://localhost:8080/",
          "height": 150
        },
        "id": "qdCUg2MR0PD2",
        "outputId": "c19ba3ab-6cd4-472e-c800-0bdfd0d1c3c5"
      },
      "source": [
        "fitted_pipe.predict('According to the most recent update there has been a major decrese in the rate of oil')"
      ],
      "execution_count": 5,
      "outputs": [
        {
          "output_type": "stream",
          "name": "stdout",
          "text": [
            "sentence_detector_dl download started this may take some time.\n",
            "Approximate size to download 354.6 KB\n",
            "[OK!]\n",
            "Warning::Spark Session already created, some configs may not take.\n"
          ]
        },
        {
          "output_type": "execute_result",
          "data": {
            "text/plain": [
              "                                            sentence  \\\n",
              "0  According to the most recent update there has ...   \n",
              "\n",
              "                sentence_embedding_small_bert_L2_128 sentiment  \\\n",
              "0  [-0.9835950136184692, 0.07015661895275116, -0....  positive   \n",
              "\n",
              "  sentiment_confidence  \n",
              "0                  1.0  "
            ],
            "text/html": [
              "\n",
              "  <div id=\"df-18d81f75-1e13-4819-8f21-82fd2413dd60\" class=\"colab-df-container\">\n",
              "    <div>\n",
              "<style scoped>\n",
              "    .dataframe tbody tr th:only-of-type {\n",
              "        vertical-align: middle;\n",
              "    }\n",
              "\n",
              "    .dataframe tbody tr th {\n",
              "        vertical-align: top;\n",
              "    }\n",
              "\n",
              "    .dataframe thead th {\n",
              "        text-align: right;\n",
              "    }\n",
              "</style>\n",
              "<table border=\"1\" class=\"dataframe\">\n",
              "  <thead>\n",
              "    <tr style=\"text-align: right;\">\n",
              "      <th></th>\n",
              "      <th>sentence</th>\n",
              "      <th>sentence_embedding_small_bert_L2_128</th>\n",
              "      <th>sentiment</th>\n",
              "      <th>sentiment_confidence</th>\n",
              "    </tr>\n",
              "  </thead>\n",
              "  <tbody>\n",
              "    <tr>\n",
              "      <th>0</th>\n",
              "      <td>According to the most recent update there has ...</td>\n",
              "      <td>[-0.9835950136184692, 0.07015661895275116, -0....</td>\n",
              "      <td>positive</td>\n",
              "      <td>1.0</td>\n",
              "    </tr>\n",
              "  </tbody>\n",
              "</table>\n",
              "</div>\n",
              "    <div class=\"colab-df-buttons\">\n",
              "\n",
              "  <div class=\"colab-df-container\">\n",
              "    <button class=\"colab-df-convert\" onclick=\"convertToInteractive('df-18d81f75-1e13-4819-8f21-82fd2413dd60')\"\n",
              "            title=\"Convert this dataframe to an interactive table.\"\n",
              "            style=\"display:none;\">\n",
              "\n",
              "  <svg xmlns=\"http://www.w3.org/2000/svg\" height=\"24px\" viewBox=\"0 -960 960 960\">\n",
              "    <path d=\"M120-120v-720h720v720H120Zm60-500h600v-160H180v160Zm220 220h160v-160H400v160Zm0 220h160v-160H400v160ZM180-400h160v-160H180v160Zm440 0h160v-160H620v160ZM180-180h160v-160H180v160Zm440 0h160v-160H620v160Z\"/>\n",
              "  </svg>\n",
              "    </button>\n",
              "\n",
              "  <style>\n",
              "    .colab-df-container {\n",
              "      display:flex;\n",
              "      gap: 12px;\n",
              "    }\n",
              "\n",
              "    .colab-df-convert {\n",
              "      background-color: #E8F0FE;\n",
              "      border: none;\n",
              "      border-radius: 50%;\n",
              "      cursor: pointer;\n",
              "      display: none;\n",
              "      fill: #1967D2;\n",
              "      height: 32px;\n",
              "      padding: 0 0 0 0;\n",
              "      width: 32px;\n",
              "    }\n",
              "\n",
              "    .colab-df-convert:hover {\n",
              "      background-color: #E2EBFA;\n",
              "      box-shadow: 0px 1px 2px rgba(60, 64, 67, 0.3), 0px 1px 3px 1px rgba(60, 64, 67, 0.15);\n",
              "      fill: #174EA6;\n",
              "    }\n",
              "\n",
              "    .colab-df-buttons div {\n",
              "      margin-bottom: 4px;\n",
              "    }\n",
              "\n",
              "    [theme=dark] .colab-df-convert {\n",
              "      background-color: #3B4455;\n",
              "      fill: #D2E3FC;\n",
              "    }\n",
              "\n",
              "    [theme=dark] .colab-df-convert:hover {\n",
              "      background-color: #434B5C;\n",
              "      box-shadow: 0px 1px 3px 1px rgba(0, 0, 0, 0.15);\n",
              "      filter: drop-shadow(0px 1px 2px rgba(0, 0, 0, 0.3));\n",
              "      fill: #FFFFFF;\n",
              "    }\n",
              "  </style>\n",
              "\n",
              "    <script>\n",
              "      const buttonEl =\n",
              "        document.querySelector('#df-18d81f75-1e13-4819-8f21-82fd2413dd60 button.colab-df-convert');\n",
              "      buttonEl.style.display =\n",
              "        google.colab.kernel.accessAllowed ? 'block' : 'none';\n",
              "\n",
              "      async function convertToInteractive(key) {\n",
              "        const element = document.querySelector('#df-18d81f75-1e13-4819-8f21-82fd2413dd60');\n",
              "        const dataTable =\n",
              "          await google.colab.kernel.invokeFunction('convertToInteractive',\n",
              "                                                    [key], {});\n",
              "        if (!dataTable) return;\n",
              "\n",
              "        const docLinkHtml = 'Like what you see? Visit the ' +\n",
              "          '<a target=\"_blank\" href=https://colab.research.google.com/notebooks/data_table.ipynb>data table notebook</a>'\n",
              "          + ' to learn more about interactive tables.';\n",
              "        element.innerHTML = '';\n",
              "        dataTable['output_type'] = 'display_data';\n",
              "        await google.colab.output.renderOutput(dataTable, element);\n",
              "        const docLink = document.createElement('div');\n",
              "        docLink.innerHTML = docLinkHtml;\n",
              "        element.appendChild(docLink);\n",
              "      }\n",
              "    </script>\n",
              "  </div>\n",
              "\n",
              "    </div>\n",
              "  </div>\n"
            ]
          },
          "metadata": {},
          "execution_count": 5
        }
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "xflpwrVjjBVD"
      },
      "source": [
        "## 5. Configure pipe training parameters"
      ]
    },
    {
      "cell_type": "code",
      "metadata": {
        "colab": {
          "base_uri": "https://localhost:8080/"
        },
        "id": "UtsAUGTmOTms",
        "outputId": "e5c0181c-13c7-4bd9-9270-4fbbd2cc1ea6"
      },
      "source": [
        "trainable_pipe.print_info()"
      ],
      "execution_count": 6,
      "outputs": [
        {
          "output_type": "stream",
          "name": "stdout",
          "text": [
            "The following parameters are configurable for this NLU pipeline (You can copy paste the examples) :\n",
            ">>> component_list['bert_sentence_embeddings@sent_small_bert_L2_128'] has settable params:\n",
            "component_list['bert_sentence_embeddings@sent_small_bert_L2_128'].setBatchSize(8)              | Info: Size of every batch | Currently set to : 8\n",
            "component_list['bert_sentence_embeddings@sent_small_bert_L2_128'].setEngine('tensorflow')      | Info: Deep Learning engine used for this model | Currently set to : tensorflow\n",
            "component_list['bert_sentence_embeddings@sent_small_bert_L2_128'].setIsLong(False)             | Info: Use Long type instead of Int type for inputs buffer - Some Bert models require Long instead of Int. | Currently set to : False\n",
            "component_list['bert_sentence_embeddings@sent_small_bert_L2_128'].setMaxSentenceLength(128)    | Info: Max sentence length to process | Currently set to : 128\n",
            "component_list['bert_sentence_embeddings@sent_small_bert_L2_128'].setDimension(128)            | Info: Number of embedding dimensions | Currently set to : 128\n",
            "component_list['bert_sentence_embeddings@sent_small_bert_L2_128'].setCaseSensitive(False)      | Info: whether to ignore case in tokens for embeddings matching | Currently set to : False\n",
            "component_list['bert_sentence_embeddings@sent_small_bert_L2_128'].setStorageRef('sent_small_bert_L2_128')  | Info: unique reference name for identification | Currently set to : sent_small_bert_L2_128\n",
            ">>> component_list['document_assembler'] has settable params:\n",
            "component_list['document_assembler'].setCleanupMode('shrink')                                  | Info: possible values: disabled, inplace, inplace_full, shrink, shrink_full, each, each_full, delete_full | Currently set to : shrink\n",
            ">>> component_list['sentiment_dl@sent_small_bert_L2_128'] has settable params:\n",
            "component_list['sentiment_dl@sent_small_bert_L2_128'].setEngine('tensorflow')                  | Info: Deep Learning engine used for this model | Currently set to : tensorflow\n",
            "component_list['sentiment_dl@sent_small_bert_L2_128'].setThreshold(0.6)                        | Info: The minimum threshold for the final result otheriwse it will be neutral | Currently set to : 0.6\n",
            "component_list['sentiment_dl@sent_small_bert_L2_128'].setThresholdLabel('neutral')             | Info: In case the score is less than threshold, what should be the label. Default is neutral. | Currently set to : neutral\n",
            "component_list['sentiment_dl@sent_small_bert_L2_128'].setStorageRef('sent_small_bert_L2_128')  | Info: unique reference name for identification | Currently set to : sent_small_bert_L2_128\n"
          ]
        }
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "2GJdDNV9jEIe"
      },
      "source": [
        "## 6. Retrain with new parameters"
      ]
    },
    {
      "cell_type": "code",
      "metadata": {
        "colab": {
          "base_uri": "https://localhost:8080/",
          "height": 719
        },
        "id": "mptfvHx-MMMX",
        "outputId": "71701494-c69a-4ea6-a803-677b18ebaffd"
      },
      "source": [
        "# Train longer!\n",
        "trainable_pipe = nlp.load('train.sentiment')\n",
        "trainable_pipe['trainable_sentiment_dl'].setMaxEpochs(5)\n",
        "fitted_pipe = trainable_pipe.fit(train_df.iloc[:100])\n",
        "# predict with the trainable pipeline on dataset and get predictions\n",
        "preds = fitted_pipe.predict(train_df.iloc[:100],output_level='document')\n",
        "\n",
        "#sentence detector that is part of the pipe generates sone NaNs. lets drop them first\n",
        "preds.dropna(inplace=True)\n",
        "print(classification_report(preds['y'], preds['sentiment']))\n",
        "\n",
        "preds"
      ],
      "execution_count": 7,
      "outputs": [
        {
          "output_type": "stream",
          "name": "stdout",
          "text": [
            "Warning::Spark Session already created, some configs may not take.\n",
            "Warning::Spark Session already created, some configs may not take.\n",
            "sent_small_bert_L2_128 download started this may take some time.\n",
            "Approximate size to download 16.1 MB\n",
            "[OK!]\n",
            "              precision    recall  f1-score   support\n",
            "\n",
            "    negative       0.00      0.00      0.00        30\n",
            "    positive       0.70      1.00      0.82        70\n",
            "\n",
            "    accuracy                           0.70       100\n",
            "   macro avg       0.35      0.50      0.41       100\n",
            "weighted avg       0.49      0.70      0.58       100\n",
            "\n"
          ]
        },
        {
          "output_type": "execute_result",
          "data": {
            "text/plain": [
              "                                             document  \\\n",
              "0   The OMX Nordic 40 OMXN40 index , comprising th...   \n",
              "1   Dubai Nokia has announced the launch of `` Com...   \n",
              "2   credit 20 November 2009 - Finnish glass techno...   \n",
              "3   HELSINKI AFX - Outokumpu said its technology u...   \n",
              "4   Helsingin Uutiset , Vantaan Sanomat and Lansiv...   \n",
              "..                                                ...   \n",
              "95  Ruukki Group calculates that it has lost EUR 4...   \n",
              "96  This is the second successful effort for the f...   \n",
              "97  For the first nine months of 2010 , Talvivaara...   \n",
              "98  Nordea sees a return to positive growth for th...   \n",
              "99  In the third quarter , net sales increased by ...   \n",
              "\n",
              "                 sentence_embedding_small_bert_L2_128 sentiment  \\\n",
              "0   [-0.5881205201148987, 0.19063492119312286, -0....  positive   \n",
              "1   [-0.37779635190963745, -0.20781250298023224, -...  positive   \n",
              "2   [-0.4517509937286377, 0.6735780239105225, -0.2...  positive   \n",
              "3   [-0.10504205524921417, 0.31528422236442566, -0...  positive   \n",
              "4   [-1.087294101715088, -0.1457926332950592, -0.1...  positive   \n",
              "..                                                ...       ...   \n",
              "95  [-1.1240153312683105, 0.029101694002747536, -0...  positive   \n",
              "96  [-1.0914063453674316, 0.636502742767334, -0.13...  positive   \n",
              "97  [-1.4264403581619263, -0.3568509817123413, -0....  positive   \n",
              "98  [-0.5386144518852234, -0.5268656611442566, -0....  positive   \n",
              "99  [-0.8460788726806641, 0.5203403830528259, -0.8...  positive   \n",
              "\n",
              "   sentiment_confidence                                               text  \\\n",
              "0                   1.0  The OMX Nordic 40 OMXN40 index , comprising th...   \n",
              "1                   1.0  Dubai Nokia has announced the launch of `` Com...   \n",
              "2                   1.0  credit 20 November 2009 - Finnish glass techno...   \n",
              "3                   1.0  HELSINKI AFX - Outokumpu said its technology u...   \n",
              "4                   1.0  Helsingin Uutiset , Vantaan Sanomat and Lansiv...   \n",
              "..                  ...                                                ...   \n",
              "95                  1.0  Ruukki Group calculates that it has lost EUR 4...   \n",
              "96                  1.0  This is the second successful effort for the f...   \n",
              "97                  1.0  For the first nine months of 2010 , Talvivaara...   \n",
              "98                  1.0  Nordea sees a return to positive growth for th...   \n",
              "99                  1.0  In the third quarter , net sales increased by ...   \n",
              "\n",
              "           y  \n",
              "0   negative  \n",
              "1   positive  \n",
              "2   positive  \n",
              "3   positive  \n",
              "4   positive  \n",
              "..       ...  \n",
              "95  negative  \n",
              "96  positive  \n",
              "97  positive  \n",
              "98  positive  \n",
              "99  positive  \n",
              "\n",
              "[100 rows x 6 columns]"
            ],
            "text/html": [
              "\n",
              "  <div id=\"df-bc12a501-a05a-4796-aecf-162b46e6f0c2\" class=\"colab-df-container\">\n",
              "    <div>\n",
              "<style scoped>\n",
              "    .dataframe tbody tr th:only-of-type {\n",
              "        vertical-align: middle;\n",
              "    }\n",
              "\n",
              "    .dataframe tbody tr th {\n",
              "        vertical-align: top;\n",
              "    }\n",
              "\n",
              "    .dataframe thead th {\n",
              "        text-align: right;\n",
              "    }\n",
              "</style>\n",
              "<table border=\"1\" class=\"dataframe\">\n",
              "  <thead>\n",
              "    <tr style=\"text-align: right;\">\n",
              "      <th></th>\n",
              "      <th>document</th>\n",
              "      <th>sentence_embedding_small_bert_L2_128</th>\n",
              "      <th>sentiment</th>\n",
              "      <th>sentiment_confidence</th>\n",
              "      <th>text</th>\n",
              "      <th>y</th>\n",
              "    </tr>\n",
              "  </thead>\n",
              "  <tbody>\n",
              "    <tr>\n",
              "      <th>0</th>\n",
              "      <td>The OMX Nordic 40 OMXN40 index , comprising th...</td>\n",
              "      <td>[-0.5881205201148987, 0.19063492119312286, -0....</td>\n",
              "      <td>positive</td>\n",
              "      <td>1.0</td>\n",
              "      <td>The OMX Nordic 40 OMXN40 index , comprising th...</td>\n",
              "      <td>negative</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>1</th>\n",
              "      <td>Dubai Nokia has announced the launch of `` Com...</td>\n",
              "      <td>[-0.37779635190963745, -0.20781250298023224, -...</td>\n",
              "      <td>positive</td>\n",
              "      <td>1.0</td>\n",
              "      <td>Dubai Nokia has announced the launch of `` Com...</td>\n",
              "      <td>positive</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>2</th>\n",
              "      <td>credit 20 November 2009 - Finnish glass techno...</td>\n",
              "      <td>[-0.4517509937286377, 0.6735780239105225, -0.2...</td>\n",
              "      <td>positive</td>\n",
              "      <td>1.0</td>\n",
              "      <td>credit 20 November 2009 - Finnish glass techno...</td>\n",
              "      <td>positive</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>3</th>\n",
              "      <td>HELSINKI AFX - Outokumpu said its technology u...</td>\n",
              "      <td>[-0.10504205524921417, 0.31528422236442566, -0...</td>\n",
              "      <td>positive</td>\n",
              "      <td>1.0</td>\n",
              "      <td>HELSINKI AFX - Outokumpu said its technology u...</td>\n",
              "      <td>positive</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>4</th>\n",
              "      <td>Helsingin Uutiset , Vantaan Sanomat and Lansiv...</td>\n",
              "      <td>[-1.087294101715088, -0.1457926332950592, -0.1...</td>\n",
              "      <td>positive</td>\n",
              "      <td>1.0</td>\n",
              "      <td>Helsingin Uutiset , Vantaan Sanomat and Lansiv...</td>\n",
              "      <td>positive</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>...</th>\n",
              "      <td>...</td>\n",
              "      <td>...</td>\n",
              "      <td>...</td>\n",
              "      <td>...</td>\n",
              "      <td>...</td>\n",
              "      <td>...</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>95</th>\n",
              "      <td>Ruukki Group calculates that it has lost EUR 4...</td>\n",
              "      <td>[-1.1240153312683105, 0.029101694002747536, -0...</td>\n",
              "      <td>positive</td>\n",
              "      <td>1.0</td>\n",
              "      <td>Ruukki Group calculates that it has lost EUR 4...</td>\n",
              "      <td>negative</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>96</th>\n",
              "      <td>This is the second successful effort for the f...</td>\n",
              "      <td>[-1.0914063453674316, 0.636502742767334, -0.13...</td>\n",
              "      <td>positive</td>\n",
              "      <td>1.0</td>\n",
              "      <td>This is the second successful effort for the f...</td>\n",
              "      <td>positive</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>97</th>\n",
              "      <td>For the first nine months of 2010 , Talvivaara...</td>\n",
              "      <td>[-1.4264403581619263, -0.3568509817123413, -0....</td>\n",
              "      <td>positive</td>\n",
              "      <td>1.0</td>\n",
              "      <td>For the first nine months of 2010 , Talvivaara...</td>\n",
              "      <td>positive</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>98</th>\n",
              "      <td>Nordea sees a return to positive growth for th...</td>\n",
              "      <td>[-0.5386144518852234, -0.5268656611442566, -0....</td>\n",
              "      <td>positive</td>\n",
              "      <td>1.0</td>\n",
              "      <td>Nordea sees a return to positive growth for th...</td>\n",
              "      <td>positive</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>99</th>\n",
              "      <td>In the third quarter , net sales increased by ...</td>\n",
              "      <td>[-0.8460788726806641, 0.5203403830528259, -0.8...</td>\n",
              "      <td>positive</td>\n",
              "      <td>1.0</td>\n",
              "      <td>In the third quarter , net sales increased by ...</td>\n",
              "      <td>positive</td>\n",
              "    </tr>\n",
              "  </tbody>\n",
              "</table>\n",
              "<p>100 rows × 6 columns</p>\n",
              "</div>\n",
              "    <div class=\"colab-df-buttons\">\n",
              "\n",
              "  <div class=\"colab-df-container\">\n",
              "    <button class=\"colab-df-convert\" onclick=\"convertToInteractive('df-bc12a501-a05a-4796-aecf-162b46e6f0c2')\"\n",
              "            title=\"Convert this dataframe to an interactive table.\"\n",
              "            style=\"display:none;\">\n",
              "\n",
              "  <svg xmlns=\"http://www.w3.org/2000/svg\" height=\"24px\" viewBox=\"0 -960 960 960\">\n",
              "    <path d=\"M120-120v-720h720v720H120Zm60-500h600v-160H180v160Zm220 220h160v-160H400v160Zm0 220h160v-160H400v160ZM180-400h160v-160H180v160Zm440 0h160v-160H620v160ZM180-180h160v-160H180v160Zm440 0h160v-160H620v160Z\"/>\n",
              "  </svg>\n",
              "    </button>\n",
              "\n",
              "  <style>\n",
              "    .colab-df-container {\n",
              "      display:flex;\n",
              "      gap: 12px;\n",
              "    }\n",
              "\n",
              "    .colab-df-convert {\n",
              "      background-color: #E8F0FE;\n",
              "      border: none;\n",
              "      border-radius: 50%;\n",
              "      cursor: pointer;\n",
              "      display: none;\n",
              "      fill: #1967D2;\n",
              "      height: 32px;\n",
              "      padding: 0 0 0 0;\n",
              "      width: 32px;\n",
              "    }\n",
              "\n",
              "    .colab-df-convert:hover {\n",
              "      background-color: #E2EBFA;\n",
              "      box-shadow: 0px 1px 2px rgba(60, 64, 67, 0.3), 0px 1px 3px 1px rgba(60, 64, 67, 0.15);\n",
              "      fill: #174EA6;\n",
              "    }\n",
              "\n",
              "    .colab-df-buttons div {\n",
              "      margin-bottom: 4px;\n",
              "    }\n",
              "\n",
              "    [theme=dark] .colab-df-convert {\n",
              "      background-color: #3B4455;\n",
              "      fill: #D2E3FC;\n",
              "    }\n",
              "\n",
              "    [theme=dark] .colab-df-convert:hover {\n",
              "      background-color: #434B5C;\n",
              "      box-shadow: 0px 1px 3px 1px rgba(0, 0, 0, 0.15);\n",
              "      filter: drop-shadow(0px 1px 2px rgba(0, 0, 0, 0.3));\n",
              "      fill: #FFFFFF;\n",
              "    }\n",
              "  </style>\n",
              "\n",
              "    <script>\n",
              "      const buttonEl =\n",
              "        document.querySelector('#df-bc12a501-a05a-4796-aecf-162b46e6f0c2 button.colab-df-convert');\n",
              "      buttonEl.style.display =\n",
              "        google.colab.kernel.accessAllowed ? 'block' : 'none';\n",
              "\n",
              "      async function convertToInteractive(key) {\n",
              "        const element = document.querySelector('#df-bc12a501-a05a-4796-aecf-162b46e6f0c2');\n",
              "        const dataTable =\n",
              "          await google.colab.kernel.invokeFunction('convertToInteractive',\n",
              "                                                    [key], {});\n",
              "        if (!dataTable) return;\n",
              "\n",
              "        const docLinkHtml = 'Like what you see? Visit the ' +\n",
              "          '<a target=\"_blank\" href=https://colab.research.google.com/notebooks/data_table.ipynb>data table notebook</a>'\n",
              "          + ' to learn more about interactive tables.';\n",
              "        element.innerHTML = '';\n",
              "        dataTable['output_type'] = 'display_data';\n",
              "        await google.colab.output.renderOutput(dataTable, element);\n",
              "        const docLink = document.createElement('div');\n",
              "        docLink.innerHTML = docLinkHtml;\n",
              "        element.appendChild(docLink);\n",
              "      }\n",
              "    </script>\n",
              "  </div>\n",
              "\n",
              "\n",
              "<div id=\"df-ed966ad0-281d-4a2d-89b2-d3b2aead084f\">\n",
              "  <button class=\"colab-df-quickchart\" onclick=\"quickchart('df-ed966ad0-281d-4a2d-89b2-d3b2aead084f')\"\n",
              "            title=\"Suggest charts.\"\n",
              "            style=\"display:none;\">\n",
              "\n",
              "<svg xmlns=\"http://www.w3.org/2000/svg\" height=\"24px\"viewBox=\"0 0 24 24\"\n",
              "     width=\"24px\">\n",
              "    <g>\n",
              "        <path d=\"M19 3H5c-1.1 0-2 .9-2 2v14c0 1.1.9 2 2 2h14c1.1 0 2-.9 2-2V5c0-1.1-.9-2-2-2zM9 17H7v-7h2v7zm4 0h-2V7h2v10zm4 0h-2v-4h2v4z\"/>\n",
              "    </g>\n",
              "</svg>\n",
              "  </button>\n",
              "\n",
              "<style>\n",
              "  .colab-df-quickchart {\n",
              "      --bg-color: #E8F0FE;\n",
              "      --fill-color: #1967D2;\n",
              "      --hover-bg-color: #E2EBFA;\n",
              "      --hover-fill-color: #174EA6;\n",
              "      --disabled-fill-color: #AAA;\n",
              "      --disabled-bg-color: #DDD;\n",
              "  }\n",
              "\n",
              "  [theme=dark] .colab-df-quickchart {\n",
              "      --bg-color: #3B4455;\n",
              "      --fill-color: #D2E3FC;\n",
              "      --hover-bg-color: #434B5C;\n",
              "      --hover-fill-color: #FFFFFF;\n",
              "      --disabled-bg-color: #3B4455;\n",
              "      --disabled-fill-color: #666;\n",
              "  }\n",
              "\n",
              "  .colab-df-quickchart {\n",
              "    background-color: var(--bg-color);\n",
              "    border: none;\n",
              "    border-radius: 50%;\n",
              "    cursor: pointer;\n",
              "    display: none;\n",
              "    fill: var(--fill-color);\n",
              "    height: 32px;\n",
              "    padding: 0;\n",
              "    width: 32px;\n",
              "  }\n",
              "\n",
              "  .colab-df-quickchart:hover {\n",
              "    background-color: var(--hover-bg-color);\n",
              "    box-shadow: 0 1px 2px rgba(60, 64, 67, 0.3), 0 1px 3px 1px rgba(60, 64, 67, 0.15);\n",
              "    fill: var(--button-hover-fill-color);\n",
              "  }\n",
              "\n",
              "  .colab-df-quickchart-complete:disabled,\n",
              "  .colab-df-quickchart-complete:disabled:hover {\n",
              "    background-color: var(--disabled-bg-color);\n",
              "    fill: var(--disabled-fill-color);\n",
              "    box-shadow: none;\n",
              "  }\n",
              "\n",
              "  .colab-df-spinner {\n",
              "    border: 2px solid var(--fill-color);\n",
              "    border-color: transparent;\n",
              "    border-bottom-color: var(--fill-color);\n",
              "    animation:\n",
              "      spin 1s steps(1) infinite;\n",
              "  }\n",
              "\n",
              "  @keyframes spin {\n",
              "    0% {\n",
              "      border-color: transparent;\n",
              "      border-bottom-color: var(--fill-color);\n",
              "      border-left-color: var(--fill-color);\n",
              "    }\n",
              "    20% {\n",
              "      border-color: transparent;\n",
              "      border-left-color: var(--fill-color);\n",
              "      border-top-color: var(--fill-color);\n",
              "    }\n",
              "    30% {\n",
              "      border-color: transparent;\n",
              "      border-left-color: var(--fill-color);\n",
              "      border-top-color: var(--fill-color);\n",
              "      border-right-color: var(--fill-color);\n",
              "    }\n",
              "    40% {\n",
              "      border-color: transparent;\n",
              "      border-right-color: var(--fill-color);\n",
              "      border-top-color: var(--fill-color);\n",
              "    }\n",
              "    60% {\n",
              "      border-color: transparent;\n",
              "      border-right-color: var(--fill-color);\n",
              "    }\n",
              "    80% {\n",
              "      border-color: transparent;\n",
              "      border-right-color: var(--fill-color);\n",
              "      border-bottom-color: var(--fill-color);\n",
              "    }\n",
              "    90% {\n",
              "      border-color: transparent;\n",
              "      border-bottom-color: var(--fill-color);\n",
              "    }\n",
              "  }\n",
              "</style>\n",
              "\n",
              "  <script>\n",
              "    async function quickchart(key) {\n",
              "      const quickchartButtonEl =\n",
              "        document.querySelector('#' + key + ' button');\n",
              "      quickchartButtonEl.disabled = true;  // To prevent multiple clicks.\n",
              "      quickchartButtonEl.classList.add('colab-df-spinner');\n",
              "      try {\n",
              "        const charts = await google.colab.kernel.invokeFunction(\n",
              "            'suggestCharts', [key], {});\n",
              "      } catch (error) {\n",
              "        console.error('Error during call to suggestCharts:', error);\n",
              "      }\n",
              "      quickchartButtonEl.classList.remove('colab-df-spinner');\n",
              "      quickchartButtonEl.classList.add('colab-df-quickchart-complete');\n",
              "    }\n",
              "    (() => {\n",
              "      let quickchartButtonEl =\n",
              "        document.querySelector('#df-ed966ad0-281d-4a2d-89b2-d3b2aead084f button');\n",
              "      quickchartButtonEl.style.display =\n",
              "        google.colab.kernel.accessAllowed ? 'block' : 'none';\n",
              "    })();\n",
              "  </script>\n",
              "</div>\n",
              "    </div>\n",
              "  </div>\n"
            ]
          },
          "metadata": {},
          "execution_count": 7
        }
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "qFoT-s1MjTSS"
      },
      "source": [
        "#7.  Try training with different Embeddings"
      ]
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "nxWFzQOhjWC8",
        "colab": {
          "base_uri": "https://localhost:8080/"
        },
        "outputId": "fae0ba7b-3630-493e-f3ed-74e126ab96d2"
      },
      "source": [
        "# We can use nlu.print_components(action='embed_sentence') to see every possibler sentence embedding we could use. Lets use bert!\n",
        "nlp.nlu.print_components(action='embed_sentence')"
      ],
      "execution_count": 8,
      "outputs": [
        {
          "output_type": "stream",
          "name": "stdout",
          "text": [
            "For language <am> NLU provides the following Models : \n",
            "nlu.load('am.embed_sentence.xlm_roberta') returns Spark NLP model_anno_obj sent_xlm_roberta_base_finetuned_amharic\n",
            "For language <de> NLU provides the following Models : \n",
            "nlu.load('de.embed_sentence.bert.base_cased') returns Spark NLP model_anno_obj sent_bert_base_cased\n",
            "For language <el> NLU provides the following Models : \n",
            "nlu.load('el.embed_sentence.bert.base_uncased') returns Spark NLP model_anno_obj sent_bert_base_uncased\n",
            "For language <en> NLU provides the following Models : \n",
            "nlu.load('en.embed_sentence') returns Spark NLP model_anno_obj tfhub_use\n",
            "nlu.load('en.embed_sentence.albert') returns Spark NLP model_anno_obj albert_base_uncased\n",
            "nlu.load('en.embed_sentence.bert') returns Spark NLP model_anno_obj sent_bert_base_uncased\n",
            "nlu.load('en.embed_sentence.bert.base_uncased_legal') returns Spark NLP model_anno_obj sent_bert_base_uncased_legal\n",
            "nlu.load('en.embed_sentence.bert.finetuned') returns Spark NLP model_anno_obj sbert_setfit_finetuned_financial_text_classification\n",
            "nlu.load('en.embed_sentence.bert.pubmed') returns Spark NLP model_anno_obj sent_bert_pubmed\n",
            "nlu.load('en.embed_sentence.bert.pubmed_squad2') returns Spark NLP model_anno_obj sent_bert_pubmed_squad2\n",
            "nlu.load('en.embed_sentence.bert.wiki_books') returns Spark NLP model_anno_obj sent_bert_wiki_books\n",
            "nlu.load('en.embed_sentence.bert.wiki_books_mnli') returns Spark NLP model_anno_obj sent_bert_wiki_books_mnli\n",
            "nlu.load('en.embed_sentence.bert.wiki_books_qnli') returns Spark NLP model_anno_obj sent_bert_wiki_books_qnli\n",
            "nlu.load('en.embed_sentence.bert.wiki_books_qqp') returns Spark NLP model_anno_obj sent_bert_wiki_books_qqp\n",
            "nlu.load('en.embed_sentence.bert.wiki_books_squad2') returns Spark NLP model_anno_obj sent_bert_wiki_books_squad2\n",
            "nlu.load('en.embed_sentence.bert.wiki_books_sst2') returns Spark NLP model_anno_obj sent_bert_wiki_books_sst2\n",
            "nlu.load('en.embed_sentence.bert_base_cased') returns Spark NLP model_anno_obj sent_bert_base_cased\n",
            "nlu.load('en.embed_sentence.bert_base_uncased') returns Spark NLP model_anno_obj sent_bert_base_uncased\n",
            "nlu.load('en.embed_sentence.bert_large_cased') returns Spark NLP model_anno_obj sent_bert_large_cased\n",
            "nlu.load('en.embed_sentence.bert_large_uncased') returns Spark NLP model_anno_obj sent_bert_large_uncased\n",
            "nlu.load('en.embed_sentence.bert_use_cmlm_en_base') returns Spark NLP model_anno_obj sent_bert_use_cmlm_en_base\n",
            "nlu.load('en.embed_sentence.bert_use_cmlm_en_large') returns Spark NLP model_anno_obj sent_bert_use_cmlm_en_large\n",
            "nlu.load('en.embed_sentence.biobert.clinical_base_cased') returns Spark NLP model_anno_obj sent_biobert_clinical_base_cased\n",
            "nlu.load('en.embed_sentence.biobert.discharge_base_cased') returns Spark NLP model_anno_obj sent_biobert_discharge_base_cased\n",
            "nlu.load('en.embed_sentence.biobert.pmc_base_cased') returns Spark NLP model_anno_obj sent_biobert_pmc_base_cased\n",
            "nlu.load('en.embed_sentence.biobert.pubmed_base_cased') returns Spark NLP model_anno_obj sent_biobert_pubmed_base_cased\n",
            "nlu.load('en.embed_sentence.biobert.pubmed_large_cased') returns Spark NLP model_anno_obj sent_biobert_pubmed_large_cased\n",
            "nlu.load('en.embed_sentence.biobert.pubmed_pmc_base_cased') returns Spark NLP model_anno_obj sent_biobert_pubmed_pmc_base_cased\n",
            "nlu.load('en.embed_sentence.covidbert.large_uncased') returns Spark NLP model_anno_obj sent_covidbert_large_uncased\n",
            "nlu.load('en.embed_sentence.distil_roberta.distilled_base') returns Spark NLP model_anno_obj sent_distilroberta_base\n",
            "nlu.load('en.embed_sentence.doc2vec') returns Spark NLP model_anno_obj doc2vec_gigaword_300\n",
            "nlu.load('en.embed_sentence.doc2vec.gigaword_300') returns Spark NLP model_anno_obj doc2vec_gigaword_300\n",
            "nlu.load('en.embed_sentence.doc2vec.gigaword_wiki_300') returns Spark NLP model_anno_obj doc2vec_gigaword_wiki_300\n",
            "nlu.load('en.embed_sentence.electra') returns Spark NLP model_anno_obj sent_electra_small_uncased\n",
            "nlu.load('en.embed_sentence.electra_base_uncased') returns Spark NLP model_anno_obj sent_electra_base_uncased\n",
            "nlu.load('en.embed_sentence.electra_large_uncased') returns Spark NLP model_anno_obj sent_electra_large_uncased\n",
            "nlu.load('en.embed_sentence.electra_small_uncased') returns Spark NLP model_anno_obj sent_electra_small_uncased\n",
            "nlu.load('en.embed_sentence.roberta.base') returns Spark NLP model_anno_obj sent_roberta_base\n",
            "nlu.load('en.embed_sentence.roberta.large') returns Spark NLP model_anno_obj sent_roberta_large\n",
            "nlu.load('en.embed_sentence.small_bert_L10_128') returns Spark NLP model_anno_obj sent_small_bert_L10_128\n",
            "nlu.load('en.embed_sentence.small_bert_L10_256') returns Spark NLP model_anno_obj sent_small_bert_L10_256\n",
            "nlu.load('en.embed_sentence.small_bert_L10_512') returns Spark NLP model_anno_obj sent_small_bert_L10_512\n",
            "nlu.load('en.embed_sentence.small_bert_L10_768') returns Spark NLP model_anno_obj sent_small_bert_L10_768\n",
            "nlu.load('en.embed_sentence.small_bert_L12_128') returns Spark NLP model_anno_obj sent_small_bert_L12_128\n",
            "nlu.load('en.embed_sentence.small_bert_L12_256') returns Spark NLP model_anno_obj sent_small_bert_L12_256\n",
            "nlu.load('en.embed_sentence.small_bert_L12_512') returns Spark NLP model_anno_obj sent_small_bert_L12_512\n",
            "nlu.load('en.embed_sentence.small_bert_L12_768') returns Spark NLP model_anno_obj sent_small_bert_L12_768\n",
            "nlu.load('en.embed_sentence.small_bert_L2_128') returns Spark NLP model_anno_obj sent_small_bert_L2_128\n",
            "nlu.load('en.embed_sentence.small_bert_L2_256') returns Spark NLP model_anno_obj sent_small_bert_L2_256\n",
            "nlu.load('en.embed_sentence.small_bert_L2_512') returns Spark NLP model_anno_obj sent_small_bert_L2_512\n",
            "nlu.load('en.embed_sentence.small_bert_L2_768') returns Spark NLP model_anno_obj sent_small_bert_L2_768\n",
            "nlu.load('en.embed_sentence.small_bert_L4_128') returns Spark NLP model_anno_obj sent_small_bert_L4_128\n",
            "nlu.load('en.embed_sentence.small_bert_L4_256') returns Spark NLP model_anno_obj sent_small_bert_L4_256\n",
            "nlu.load('en.embed_sentence.small_bert_L4_512') returns Spark NLP model_anno_obj sent_small_bert_L4_512\n",
            "nlu.load('en.embed_sentence.small_bert_L4_768') returns Spark NLP model_anno_obj sent_small_bert_L4_768\n",
            "nlu.load('en.embed_sentence.small_bert_L6_128') returns Spark NLP model_anno_obj sent_small_bert_L6_128\n",
            "nlu.load('en.embed_sentence.small_bert_L6_256') returns Spark NLP model_anno_obj sent_small_bert_L6_256\n",
            "nlu.load('en.embed_sentence.small_bert_L6_512') returns Spark NLP model_anno_obj sent_small_bert_L6_512\n",
            "nlu.load('en.embed_sentence.small_bert_L6_768') returns Spark NLP model_anno_obj sent_small_bert_L6_768\n",
            "nlu.load('en.embed_sentence.small_bert_L8_128') returns Spark NLP model_anno_obj sent_small_bert_L8_128\n",
            "nlu.load('en.embed_sentence.small_bert_L8_256') returns Spark NLP model_anno_obj sent_small_bert_L8_256\n",
            "nlu.load('en.embed_sentence.small_bert_L8_512') returns Spark NLP model_anno_obj sent_small_bert_L8_512\n",
            "nlu.load('en.embed_sentence.small_bert_L8_768') returns Spark NLP model_anno_obj sent_small_bert_L8_768\n",
            "nlu.load('en.embed_sentence.tfhub_use') returns Spark NLP model_anno_obj tfhub_use\n",
            "nlu.load('en.embed_sentence.tfhub_use.lg') returns Spark NLP model_anno_obj tfhub_use_lg\n",
            "nlu.load('en.embed_sentence.use') returns Spark NLP model_anno_obj tfhub_use\n",
            "nlu.load('en.embed_sentence.use.lg') returns Spark NLP model_anno_obj tfhub_use_lg\n",
            "For language <es> NLU provides the following Models : \n",
            "nlu.load('es.embed_sentence.bert.base_cased') returns Spark NLP model_anno_obj sent_bert_base_cased\n",
            "nlu.load('es.embed_sentence.bert.base_uncased') returns Spark NLP model_anno_obj sent_bert_base_uncased\n",
            "For language <fi> NLU provides the following Models : \n",
            "nlu.load('fi.embed_sentence.bert') returns Spark NLP model_anno_obj bert_base_finnish_uncased\n",
            "nlu.load('fi.embed_sentence.bert.cased') returns Spark NLP model_anno_obj bert_base_finnish_cased\n",
            "nlu.load('fi.embed_sentence.bert.uncased') returns Spark NLP model_anno_obj bert_base_finnish_uncased\n",
            "For language <ha> NLU provides the following Models : \n",
            "nlu.load('ha.embed_sentence.xlm_roberta') returns Spark NLP model_anno_obj sent_xlm_roberta_base_finetuned_hausa\n",
            "For language <ig> NLU provides the following Models : \n",
            "nlu.load('ig.embed_sentence.xlm_roberta') returns Spark NLP model_anno_obj sent_xlm_roberta_base_finetuned_igbo\n",
            "For language <lg> NLU provides the following Models : \n",
            "nlu.load('lg.embed_sentence.xlm_roberta') returns Spark NLP model_anno_obj sent_xlm_roberta_base_finetuned_luganda\n",
            "For language <nl> NLU provides the following Models : \n",
            "nlu.load('nl.embed_sentence.bert.base_cased') returns Spark NLP model_anno_obj sent_bert_base_cased\n",
            "For language <pcm> NLU provides the following Models : \n",
            "nlu.load('pcm.embed_sentence.xlm_roberta') returns Spark NLP model_anno_obj sent_xlm_roberta_base_finetuned_naija\n",
            "For language <pt> NLU provides the following Models : \n",
            "nlu.load('pt.embed_sentence.bert.base_legal') returns Spark NLP model_anno_obj sbert_legal_bertimbau_base_tsdae_sts\n",
            "nlu.load('pt.embed_sentence.bert.cased_large_legal') returns Spark NLP model_anno_obj sbert_bert_large_portuguese_cased_legal_mlm_sts_v0.1\n",
            "nlu.load('pt.embed_sentence.bert.large_legal') returns Spark NLP model_anno_obj sbert_legal_bertimbau_large_gpl_sts\n",
            "nlu.load('pt.embed_sentence.bert.legal.cased_large_mlm_sts_v0.10.by_stjiris') returns Spark NLP model_anno_obj sbert_bert_large_portuguese_cased_legal_mlm_sts_v0.10\n",
            "nlu.load('pt.embed_sentence.bert.legal.cased_large_mlm_sts_v0.2.by_stjiris') returns Spark NLP model_anno_obj sbert_bert_large_portuguese_cased_legal_mlm_sts_v0.2\n",
            "nlu.load('pt.embed_sentence.bert.legal.cased_large_mlm_sts_v0.3.by_stjiris') returns Spark NLP model_anno_obj sbert_bert_large_portuguese_cased_legal_mlm_sts_v0.3\n",
            "nlu.load('pt.embed_sentence.bert.legal.cased_large_mlm_sts_v0.4.by_stjiris') returns Spark NLP model_anno_obj sbert_bert_large_portuguese_cased_legal_mlm_sts_v0.4\n",
            "nlu.load('pt.embed_sentence.bert.legal.cased_large_mlm_sts_v0.5.by_stjiris') returns Spark NLP model_anno_obj sbert_bert_large_portuguese_cased_legal_mlm_sts_v0.5\n",
            "nlu.load('pt.embed_sentence.bert.legal.cased_large_mlm_sts_v0.7.by_stjiris') returns Spark NLP model_anno_obj sbert_bert_large_portuguese_cased_legal_mlm_sts_v0.7\n",
            "nlu.load('pt.embed_sentence.bert.legal.cased_large_mlm_sts_v0.8.by_stjiris') returns Spark NLP model_anno_obj sbert_bert_large_portuguese_cased_legal_mlm_sts_v0.8\n",
            "nlu.load('pt.embed_sentence.bert.legal.cased_large_mlm_sts_v0.9.by_stjiris') returns Spark NLP model_anno_obj sbert_bert_large_portuguese_cased_legal_mlm_sts_v0.9\n",
            "nlu.load('pt.embed_sentence.bert.legal.cased_large_mlm_sts_v1.0.by_stjiris') returns Spark NLP model_anno_obj sbert_bert_large_portuguese_cased_legal_mlm_sts_v1.0\n",
            "nlu.load('pt.embed_sentence.bert.legal.cased_large_mlm_v0.11_gpl_nli_sts_v0.by_stjiris') returns Spark NLP model_anno_obj sbert_bert_large_portuguese_cased_legal_mlm_v0.11_gpl_nli_sts_v0\n",
            "nlu.load('pt.embed_sentence.bert.legal.cased_large_mlm_v0.11_gpl_nli_sts_v1.by_stjiris') returns Spark NLP model_anno_obj sbert_bert_large_portuguese_cased_legal_mlm_v0.11_gpl_nli_sts_v1\n",
            "nlu.load('pt.embed_sentence.bert.legal.cased_large_mlm_v0.11_nli_sts_v0.by_stjiris') returns Spark NLP model_anno_obj sbert_bert_large_portuguese_cased_legal_mlm_v0.11_nli_sts_v0\n",
            "nlu.load('pt.embed_sentence.bert.legal.cased_large_mlm_v0.11_nli_sts_v1.by_stjiris') returns Spark NLP model_anno_obj sbert_bert_large_portuguese_cased_legal_mlm_v0.11_nli_sts_v1\n",
            "nlu.load('pt.embed_sentence.bert.legal.cased_large_mlm_v0.11_sts_v0.by_stjiris') returns Spark NLP model_anno_obj sbert_bert_large_portuguese_cased_legal_mlm_v0.11_sts_v0\n",
            "nlu.load('pt.embed_sentence.bert.legal.cased_large_mlm_v0.11_sts_v1.by_stjiris') returns Spark NLP model_anno_obj sbert_bert_large_portuguese_cased_legal_mlm_v0.11_sts_v1\n",
            "nlu.load('pt.embed_sentence.bert.v2_base_legal') returns Spark NLP model_anno_obj sbert_legal_bertimbau_sts_base_ma_v2\n",
            "nlu.load('pt.embed_sentence.bert.v2_large_legal') returns Spark NLP model_anno_obj sbert_legal_bertimbau_large_tsdae_sts_v2\n",
            "nlu.load('pt.embed_sentence.bertimbau.legal.assin.base.by_rufimelo') returns Spark NLP model_anno_obj sbert_legal_bertimbau_sts_base_ma\n",
            "nlu.load('pt.embed_sentence.bertimbau.legal.assin2.base.by_rufimelo') returns Spark NLP model_anno_obj sbert_legal_bertimbau_sts_base\n",
            "nlu.load('pt.embed_sentence.bertimbau.legal.large_sts_by_rufimelo') returns Spark NLP model_anno_obj sbert_legal_bertimbau_sts_large\n",
            "nlu.load('pt.embed_sentence.bertimbau.legal.large_sts_ma.by_rufimelo') returns Spark NLP model_anno_obj sbert_legal_bertimbau_sts_large_ma\n",
            "nlu.load('pt.embed_sentence.bertimbau.legal.large_sts_ma_v3.by_rufimelo') returns Spark NLP model_anno_obj sbert_legal_bertimbau_sts_large_ma_v3\n",
            "nlu.load('pt.embed_sentence.bertimbau.legal.large_tsdae_sts.by_rufimelo') returns Spark NLP model_anno_obj sbert_legal_bertimbau_large_tsdae_sts\n",
            "nlu.load('pt.embed_sentence.bertimbau.legal.large_tsdae_sts_v4.by_rufimelo') returns Spark NLP model_anno_obj sbert_legal_bertimbau_large_tsdae_sts_v4\n",
            "nlu.load('pt.embed_sentence.bertimbau.legal.large_tsdae_v4_gpl_sts.by_rufimelo') returns Spark NLP model_anno_obj sbert_legal_bertimbau_large_tsdae_v4_gpl_sts\n",
            "nlu.load('pt.embed_sentence.bertimbau.legal.v2_large_sts_v2.by_rufimelo') returns Spark NLP model_anno_obj sbert_legal_bertimbau_sts_large_v2\n",
            "nlu.load('pt.embed_sentence.bertimbau.legal.v2_large_v2_sts.by_rufimelo') returns Spark NLP model_anno_obj sbert_legal_bertimbau_large_v2_sts\n",
            "For language <rw> NLU provides the following Models : \n",
            "nlu.load('rw.embed_sentence.xlm_roberta') returns Spark NLP model_anno_obj sent_xlm_roberta_base_finetuned_kinyarwanda\n",
            "For language <sv> NLU provides the following Models : \n",
            "nlu.load('sv.embed_sentence.bert.base_cased') returns Spark NLP model_anno_obj sent_bert_base_cased\n",
            "For language <sw> NLU provides the following Models : \n",
            "nlu.load('sw.embed_sentence.xlm_roberta') returns Spark NLP model_anno_obj sent_xlm_roberta_base_finetuned_swahili\n",
            "For language <wo> NLU provides the following Models : \n",
            "nlu.load('wo.embed_sentence.xlm_roberta') returns Spark NLP model_anno_obj sent_xlm_roberta_base_finetuned_wolof\n",
            "For language <xx> NLU provides the following Models : \n",
            "nlu.load('xx.embed_sentence') returns Spark NLP model_anno_obj sent_bert_multi_cased\n",
            "nlu.load('xx.embed_sentence.bert') returns Spark NLP model_anno_obj sent_bert_multi_cased\n",
            "nlu.load('xx.embed_sentence.bert.cased') returns Spark NLP model_anno_obj sent_bert_multi_cased\n",
            "nlu.load('xx.embed_sentence.bert.muril') returns Spark NLP model_anno_obj sent_bert_muril\n",
            "nlu.load('xx.embed_sentence.bert_use_cmlm_multi_base') returns Spark NLP model_anno_obj sent_bert_use_cmlm_multi_base\n",
            "nlu.load('xx.embed_sentence.bert_use_cmlm_multi_base_br') returns Spark NLP model_anno_obj sent_bert_use_cmlm_multi_base_br\n",
            "nlu.load('xx.embed_sentence.labse') returns Spark NLP model_anno_obj labse\n",
            "nlu.load('xx.embed_sentence.xlm_roberta.base') returns Spark NLP model_anno_obj sent_xlm_roberta_base\n",
            "For language <yo> NLU provides the following Models : \n",
            "nlu.load('yo.embed_sentence.xlm_roberta') returns Spark NLP model_anno_obj sent_xlm_roberta_base_finetuned_yoruba\n",
            "For language <zh> NLU provides the following Models : \n",
            "nlu.load('zh.embed_sentence.bert') returns Spark NLP model_anno_obj sbert_chinese_qmc_finance_v1\n",
            "nlu.load('zh.embed_sentence.bert.distilled') returns Spark NLP model_anno_obj sbert_chinese_qmc_finance_v1_distill\n"
          ]
        }
      ]
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "IKK_Ii_gjJfF",
        "colab": {
          "base_uri": "https://localhost:8080/"
        },
        "outputId": "7e528684-a7d5-431a-ca4b-626adf50a7e9"
      },
      "source": [
        "trainable_pipe = nlp.load('en.embed_sentence.small_bert_L12_768 train.sentiment')\n",
        "# We need to train longer and user smaller LR for NON-USE based sentence embeddings usually\n",
        "# We could tune the hyperparameters further with hyperparameter tuning methods like gridsearch\n",
        "# Also longer training gives more accuracy\n",
        "trainable_pipe['trainable_sentiment_dl'].setMaxEpochs(70)\n",
        "trainable_pipe['trainable_sentiment_dl'].setLr(0.0005)\n",
        "fitted_pipe = trainable_pipe.fit(train_df)\n",
        "# predict with the trainable pipeline on dataset and get predictions\n",
        "preds = fitted_pipe.predict(train_df,output_level='document')\n",
        "\n",
        "#sentence detector that is part of the pipe generates sone NaNs. lets drop them first\n",
        "preds.dropna(inplace=True)\n",
        "print(classification_report(preds['y'], preds['sentiment']))\n",
        "\n",
        "#preds"
      ],
      "execution_count": 9,
      "outputs": [
        {
          "output_type": "stream",
          "name": "stdout",
          "text": [
            "Warning::Spark Session already created, some configs may not take.\n",
            "Warning::Spark Session already created, some configs may not take.\n",
            "sent_small_bert_L12_768 download started this may take some time.\n",
            "Approximate size to download 392.9 MB\n",
            "[OK!]\n",
            "              precision    recall  f1-score   support\n",
            "\n",
            "    negative       0.88      0.82      0.85       482\n",
            "     neutral       0.00      0.00      0.00         0\n",
            "    positive       0.96      0.92      0.94      1091\n",
            "\n",
            "    accuracy                           0.89      1573\n",
            "   macro avg       0.61      0.58      0.60      1573\n",
            "weighted avg       0.94      0.89      0.91      1573\n",
            "\n"
          ]
        }
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "_1jxw3GnVGlI"
      },
      "source": [
        "# 7.1 evaluate on Test Data"
      ]
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "Fxx4yNkNVGFl",
        "colab": {
          "base_uri": "https://localhost:8080/"
        },
        "outputId": "fdb96659-2395-48af-dd53-673b935bd767"
      },
      "source": [
        "preds = fitted_pipe.predict(test_df,output_level='document')\n",
        "\n",
        "#sentence detector that is part of the pipe generates sone NaNs. lets drop them first\n",
        "preds.dropna(inplace=True)\n",
        "print(classification_report(preds['y'], preds['sentiment']))"
      ],
      "execution_count": 10,
      "outputs": [
        {
          "output_type": "stream",
          "name": "stdout",
          "text": [
            "              precision    recall  f1-score   support\n",
            "\n",
            "    negative       0.81      0.75      0.78       122\n",
            "     neutral       0.00      0.00      0.00         0\n",
            "    positive       0.92      0.89      0.90       272\n",
            "\n",
            "    accuracy                           0.85       394\n",
            "   macro avg       0.58      0.55      0.56       394\n",
            "weighted avg       0.88      0.85      0.86       394\n",
            "\n"
          ]
        }
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "2BB-NwZUoHSe"
      },
      "source": [
        "# 8. Lets save the model"
      ]
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "eLex095goHwm"
      },
      "source": [
        "stored_model_path = './models/classifier_dl_trained'\n",
        "fitted_pipe.save(stored_model_path)"
      ],
      "execution_count": 11,
      "outputs": []
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "e_b2DPd4rCiU"
      },
      "source": [
        "# 9. Lets load the model from HDD.\n",
        "This makes Offlien NLU usage possible!   \n",
        "You need to call nlu.load(path=path_to_the_pipe) to load a model/pipeline from disk."
      ]
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "SO4uz45MoRgp",
        "colab": {
          "base_uri": "https://localhost:8080/",
          "height": 133
        },
        "outputId": "a59aec27-0b97-463f-a8a3-52de96bed3ee"
      },
      "source": [
        "hdd_pipe = nlp.load(path=stored_model_path)\n",
        "\n",
        "preds = hdd_pipe.predict('According to the most recent update there has been a major decrese in the rate of oil')\n",
        "preds"
      ],
      "execution_count": 12,
      "outputs": [
        {
          "output_type": "stream",
          "name": "stdout",
          "text": [
            "Warning::Spark Session already created, some configs may not take.\n",
            "Warning::Spark Session already created, some configs may not take.\n",
            "Warning::Spark Session already created, some configs may not take.\n"
          ]
        },
        {
          "output_type": "execute_result",
          "data": {
            "text/plain": [
              "                                            document  \\\n",
              "0  According to the most recent update there has ...   \n",
              "\n",
              "                        sentence_embedding_from_disk sentiment  \\\n",
              "0  [-0.02168591320514679, 0.13073040544986725, 0....  negative   \n",
              "\n",
              "  sentiment_confidence  \n",
              "0                  0.0  "
            ],
            "text/html": [
              "\n",
              "  <div id=\"df-4bdff0a7-4462-4915-a4fb-fa2f3ad3a855\" class=\"colab-df-container\">\n",
              "    <div>\n",
              "<style scoped>\n",
              "    .dataframe tbody tr th:only-of-type {\n",
              "        vertical-align: middle;\n",
              "    }\n",
              "\n",
              "    .dataframe tbody tr th {\n",
              "        vertical-align: top;\n",
              "    }\n",
              "\n",
              "    .dataframe thead th {\n",
              "        text-align: right;\n",
              "    }\n",
              "</style>\n",
              "<table border=\"1\" class=\"dataframe\">\n",
              "  <thead>\n",
              "    <tr style=\"text-align: right;\">\n",
              "      <th></th>\n",
              "      <th>document</th>\n",
              "      <th>sentence_embedding_from_disk</th>\n",
              "      <th>sentiment</th>\n",
              "      <th>sentiment_confidence</th>\n",
              "    </tr>\n",
              "  </thead>\n",
              "  <tbody>\n",
              "    <tr>\n",
              "      <th>0</th>\n",
              "      <td>According to the most recent update there has ...</td>\n",
              "      <td>[-0.02168591320514679, 0.13073040544986725, 0....</td>\n",
              "      <td>negative</td>\n",
              "      <td>0.0</td>\n",
              "    </tr>\n",
              "  </tbody>\n",
              "</table>\n",
              "</div>\n",
              "    <div class=\"colab-df-buttons\">\n",
              "\n",
              "  <div class=\"colab-df-container\">\n",
              "    <button class=\"colab-df-convert\" onclick=\"convertToInteractive('df-4bdff0a7-4462-4915-a4fb-fa2f3ad3a855')\"\n",
              "            title=\"Convert this dataframe to an interactive table.\"\n",
              "            style=\"display:none;\">\n",
              "\n",
              "  <svg xmlns=\"http://www.w3.org/2000/svg\" height=\"24px\" viewBox=\"0 -960 960 960\">\n",
              "    <path d=\"M120-120v-720h720v720H120Zm60-500h600v-160H180v160Zm220 220h160v-160H400v160Zm0 220h160v-160H400v160ZM180-400h160v-160H180v160Zm440 0h160v-160H620v160ZM180-180h160v-160H180v160Zm440 0h160v-160H620v160Z\"/>\n",
              "  </svg>\n",
              "    </button>\n",
              "\n",
              "  <style>\n",
              "    .colab-df-container {\n",
              "      display:flex;\n",
              "      gap: 12px;\n",
              "    }\n",
              "\n",
              "    .colab-df-convert {\n",
              "      background-color: #E8F0FE;\n",
              "      border: none;\n",
              "      border-radius: 50%;\n",
              "      cursor: pointer;\n",
              "      display: none;\n",
              "      fill: #1967D2;\n",
              "      height: 32px;\n",
              "      padding: 0 0 0 0;\n",
              "      width: 32px;\n",
              "    }\n",
              "\n",
              "    .colab-df-convert:hover {\n",
              "      background-color: #E2EBFA;\n",
              "      box-shadow: 0px 1px 2px rgba(60, 64, 67, 0.3), 0px 1px 3px 1px rgba(60, 64, 67, 0.15);\n",
              "      fill: #174EA6;\n",
              "    }\n",
              "\n",
              "    .colab-df-buttons div {\n",
              "      margin-bottom: 4px;\n",
              "    }\n",
              "\n",
              "    [theme=dark] .colab-df-convert {\n",
              "      background-color: #3B4455;\n",
              "      fill: #D2E3FC;\n",
              "    }\n",
              "\n",
              "    [theme=dark] .colab-df-convert:hover {\n",
              "      background-color: #434B5C;\n",
              "      box-shadow: 0px 1px 3px 1px rgba(0, 0, 0, 0.15);\n",
              "      filter: drop-shadow(0px 1px 2px rgba(0, 0, 0, 0.3));\n",
              "      fill: #FFFFFF;\n",
              "    }\n",
              "  </style>\n",
              "\n",
              "    <script>\n",
              "      const buttonEl =\n",
              "        document.querySelector('#df-4bdff0a7-4462-4915-a4fb-fa2f3ad3a855 button.colab-df-convert');\n",
              "      buttonEl.style.display =\n",
              "        google.colab.kernel.accessAllowed ? 'block' : 'none';\n",
              "\n",
              "      async function convertToInteractive(key) {\n",
              "        const element = document.querySelector('#df-4bdff0a7-4462-4915-a4fb-fa2f3ad3a855');\n",
              "        const dataTable =\n",
              "          await google.colab.kernel.invokeFunction('convertToInteractive',\n",
              "                                                    [key], {});\n",
              "        if (!dataTable) return;\n",
              "\n",
              "        const docLinkHtml = 'Like what you see? Visit the ' +\n",
              "          '<a target=\"_blank\" href=https://colab.research.google.com/notebooks/data_table.ipynb>data table notebook</a>'\n",
              "          + ' to learn more about interactive tables.';\n",
              "        element.innerHTML = '';\n",
              "        dataTable['output_type'] = 'display_data';\n",
              "        await google.colab.output.renderOutput(dataTable, element);\n",
              "        const docLink = document.createElement('div');\n",
              "        docLink.innerHTML = docLinkHtml;\n",
              "        element.appendChild(docLink);\n",
              "      }\n",
              "    </script>\n",
              "  </div>\n",
              "\n",
              "    </div>\n",
              "  </div>\n"
            ]
          },
          "metadata": {},
          "execution_count": 12
        }
      ]
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "e0CVlkk9v6Qi",
        "colab": {
          "base_uri": "https://localhost:8080/"
        },
        "outputId": "0f3fa874-643e-4ff5-e0f4-0060f585fbfa"
      },
      "source": [
        "hdd_pipe.print_info()"
      ],
      "execution_count": 13,
      "outputs": [
        {
          "output_type": "stream",
          "name": "stdout",
          "text": [
            "The following parameters are configurable for this NLU pipeline (You can copy paste the examples) :\n",
            ">>> component_list['document_assembler'] has settable params:\n",
            "component_list['document_assembler'].setCleanupMode('shrink')                                    | Info: possible values: disabled, inplace, inplace_full, shrink, shrink_full, each, each_full, delete_full | Currently set to : shrink\n",
            ">>> component_list['bert_sentence_embeddings@sent_small_bert_L12_768'] has settable params:\n",
            "component_list['bert_sentence_embeddings@sent_small_bert_L12_768'].setBatchSize(8)               | Info: Size of every batch | Currently set to : 8\n",
            "component_list['bert_sentence_embeddings@sent_small_bert_L12_768'].setCaseSensitive(False)       | Info: whether to ignore case in tokens for embeddings matching | Currently set to : False\n",
            "component_list['bert_sentence_embeddings@sent_small_bert_L12_768'].setDimension(768)             | Info: Number of embedding dimensions | Currently set to : 768\n",
            "component_list['bert_sentence_embeddings@sent_small_bert_L12_768'].setMaxSentenceLength(128)     | Info: Max sentence length to process | Currently set to : 128\n",
            "component_list['bert_sentence_embeddings@sent_small_bert_L12_768'].setEngine('tensorflow')       | Info: Deep Learning engine used for this model | Currently set to : tensorflow\n",
            "component_list['bert_sentence_embeddings@sent_small_bert_L12_768'].setIsLong(False)              | Info: Use Long type instead of Int type for inputs buffer - Some Bert models require Long instead of Int. | Currently set to : False\n",
            "component_list['bert_sentence_embeddings@sent_small_bert_L12_768'].setStorageRef('sent_small_bert_L12_768')  | Info: unique reference name for identification | Currently set to : sent_small_bert_L12_768\n",
            ">>> component_list['sentiment_dl@sent_small_bert_L12_768'] has settable params:\n",
            "component_list['sentiment_dl@sent_small_bert_L12_768'].setThreshold(0.6)                         | Info: The minimum threshold for the final result otheriwse it will be neutral | Currently set to : 0.6\n",
            "component_list['sentiment_dl@sent_small_bert_L12_768'].setThresholdLabel('neutral')              | Info: In case the score is less than threshold, what should be the label. Default is neutral. | Currently set to : neutral\n",
            "component_list['sentiment_dl@sent_small_bert_L12_768'].setEngine('tensorflow')                   | Info: Deep Learning engine used for this model | Currently set to : tensorflow\n",
            "component_list['sentiment_dl@sent_small_bert_L12_768'].setClasses(['positive', 'negative'])      | Info: get the tags used to trained this SentimentDLModel | Currently set to : ['positive', 'negative']\n",
            "component_list['sentiment_dl@sent_small_bert_L12_768'].setStorageRef('sent_small_bert_L12_768')  | Info: unique reference name for identification | Currently set to : sent_small_bert_L12_768\n"
          ]
        }
      ]
    }
  ]
}